Strange behaviour in bash - while loop
Hi
I have a textfile with servers that is being read by a backup script in a while loop. Here is it, simplified a bit: servers.txt: Quote:
This works fine: Code:
cat servers.txt | Code:
cat servers.txt | Is there perhaps a different way to read thru a textfile, without using pipes? |
I dont know if this is the best way, but this is how i do it and works for me
( read LINE; while [ -n "$LINE" ] do # do the same things you were doing before read LINE; done ) < servers.txt |
Thank you. I tried it, but it behaves the same. Without the ssh command, it works fine, but with it, it stops after the first line.
I guess I have to read the textfile into an array and then loop thru it, as it seems the piping gets messed up by the ssh. So I'll try to change it to an array then. |
Hi,
ssh inherits stdin, which makes the pipe (cat ... | while ...) useless. Use ssh's -n option to get around this behavior. I.e: Code:
cat servers.txt | |
Thank you!
I had already changed the script to read into an array. It was a bit of work since variables read in a pipe would lose their value when done. So I changed it to ksh and it worked. Your solution is a lot simpler, and also, now I understand why it behaved the way it did. :) |
All times are GMT -5. The time now is 01:02 AM. |