Bash While Read. 5 the reason that the loop doesn't function properly is because read is reading from stdin in both cases. Web 1 answer sorted by:
Bash Scripting While Loop Hacking Truth
The_list=$ (.code.) while read line do echo $line done < $the_list. You need to open an alternate file descriptor to your file and read from the file descriptor. Read the prompt waits for the user input. True always succeeds, and false always fails. The most direct fix is to explicitly compare $finished to the string true. Awk ' {print $2}' home/dir/file.txt | while read num do if [ $num = 0 ]; As other have pointed out, awk redirection occur later. Echo produces a single line of output, which the first call to read consumes entirely. Web the problem is that the while loop only reads the first line, ignoring the others. I want to ssh into a set of machines and check whether they are available (accepting connections and not being used).
I mentioned that true and false are also commands: While [ $finished != true ]; The terminal returns to its normal state. Echo produces a single line of output, which the first call to read consumes entirely. Echo $reply the $reply variable stores the read command message. Web it reads once; I just started learning shell and confused on how a read line (variable) command reads the file in. As example lets print all users from the /etc/passwd file: The_list=$ (.code.) while read line do echo $line done < $the_list. Write the command and press enter: I have created a small script, tssh, which does just that: