LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash: ssh from within while loop doesn't work properly (https://www.linuxquestions.org/questions/programming-9/bash-ssh-from-within-while-loop-doesnt-work-properly-675026/)

peter.lovell 10-08-2008 07:21 AM

bash: ssh from within while loop doesn't work properly
 
Hi

Can anybody explain why the following problem occur and maybe how to get around it:


The following bash code

echo -e "Pedro\nPedroAgain" | while read S
do
echo S = $S;
ssh enter_ipaddress_here ls -l
done
echo FINISHED


outputs

S = Pedro
total 192
drwxrwxr-x 7 root root 4096 Oct 3 10:24 tmp
FINISHED


I was expecting the following output:

S = Pedro
total 192
drwxrwxr-x 7 root root 4096 Oct 3 10:24 tmp
S = PedroAgain
total 192
drwxrwxr-x 7 root root 4096 Oct 3 10:24 tmp
FINISHED



A corresponding test 'for'-loop works:

for S in Pedro PedroAgain
do
echo S = $S
ssh enter_ipaddress_here ls -l
done
echo FINISHED



The above codes snippets are just piece of test code to illustrate the problem I have in my real script. I wanna use a while loop and not a for loop since I only got the "while read" loop to work for reading full rows in a file without breaking up a row when there is a white spaces within the row.


I would be grateful for any help.

Cheers
Peter Lovell

Guttorm 10-08-2008 07:33 AM

Hi

I had the same problem a while ago:

http://www.linuxquestions.org/questi...ght=while+loop

peter.lovell 10-08-2008 07:44 AM

Thanks!!!
 
I get it, tried it and my script works as it is suppose to again.
Swift reply, thanks a lot.
Peter


All times are GMT -5. The time now is 03:01 PM.