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
|