read
ShellFundamentals In simulator In real LinuxRead a line of input into variables
Name: read
You can practise it right away in the simulator, and use it in real Linux mode too.
Description
read is a shell builtin that reads a line from standard input, splits it on whitespace and assigns the pieces to the named variables, the last one getting the rest.
The idiom while IFS= read -r line processes a file line by line; -p shows a prompt, -s hides input (passwords) and -t sets a timeout.
Syntax
read [OPTION]... [NAME]...Common options
| -r | Don't treat backslashes as escapes |
| -p PROMPT | Show a prompt first |
| -s | Don't echo input (for passwords) |
| -t TIMEOUT | Wait at most TIMEOUT seconds; fail on timeout |
| -n NCHARS | Return after NCHARS characters, without Enter |
| -a ARRAY | Store the words in the array ARRAY |
| -d DELIM | Read up to the character DELIM (instead of a newline) |