I am familiar with the following code to read every line of a file and perform some command.
while read -r line; do
echo "$line"
done < filename
The above loop is driven by each line in the file with a block of operations performed in the loop.
I have a script with nested loops that spawn and control threads. I want to be able to pull a line at a time from the file by command in the loop instead of having the line frame the loop. For example, in other languages, there would be an fopen()
then an fread()
and an fclose()
toward the end of the program to clean up. Is there an equivalent in bash?
I'm using Ubuntu 18.04 LTS and bash 4.4.20