Standard Input / Output
Standard input
read
read [-r] [varname]*
- -r : Backslash does not act as
an escape character.
- Reads a line from standard input and stores it in the specified variables.
- If no variables are specified, the user input is stored in the special shell variable REPLY
- Stores one piece of data (text separated by white space) per variable, except for the last variable, which holds all remaining data from the line of user input.
echo Enter a value
read index
echo Input: $index
echo "Enter another value"
read
echo "Input: $REPLY"
# Read a file line-by-line
cat $file | while read line; do
echo ${line}
done
Standard error
Suppressing errors
cmd 2> /dev/null # Suppress error messages
cmd >& /dev/null # Suppress error messages and standard output
Resources URL:
notes/bash/resources
Sources URL:
notes/bash/sources