From the original post:
The following (save as
rr.sh) reads a file passed as an argument line by line:
#!/bin/bash while IFS='' read -r line || [[ -n "$line" ]]; do echo "Text read from file: $line" done < "$1"
IFS=) prevents leading/trailing whitespace from being trimmed.
-rprevents backslash escapes from being interpreted.
|| [[ -n $line ]]prevents the last line from being ignored if it doesn’t end with a
readreturns a non-zero exit code when it encounters EOF).
Run the script as follows:
chmod +x rr.sh ./rr.sh filename.txt