Read from standard input. One line is read from the standard input and the read contents are stored in the shell variable.
File(pra1.sh)Contents
#!/bin/bash
read -p 'Please enter the file name' fh
echo $fh
-p: Set user input information as standard input fh: Arbitrary variable name Standard input information is stored here $ fh: Display stored user input information
Execution result
$ ./pra1.sh
Please enter a file name Hello World
Hello World
Reads the contents of the file string.txt and outputs it to standard output.
Contents of job definition script
Example of use
while read LINE
do
echo "$LINE"
done < string.txt
Recommended Posts