Strange result of eval, how does eval really work with ssh?

Hi all,

some small script with eval turned me to crazy.

my OS is linux

Linux s10-1310 2.6.16.53-0.8.PTF.434477.3.TDC.0-smp #1 SMP Fri Aug 31 06:07:27 PDT 2007 x86_64 x86_64 x86_64 GNU/Linux

below script works well

#!/bin/bash
eval ssh remotehost date
eval ssh remotehost ls

below script works also well

echo "ls
ls -l" | while read line;do
eval $line
done

then below script has issue that only first line of command got executed

echo "ssh remotehost date
ssh remotehost ls" | while read line;do
eval $line
done

i was thinking maybe eval break the loop, but below script do print out the "-----" line

echo "ssh remotehost date
ssh remotehost ls" | while read line;do
eval $line
echo "----"
done

so what wrong here, please kindly help.

I'm not sure what you are trying to accomplish, but it smells dangerous.
In here:

you would call 'eval <file>' for each file on the remote system. You almost certainly don't want to do that.
If there was a file named 'rm -rf $dir' in that dir, with your loop you'd execute just that! It's not good to use eval unless you're sure that eval's argument is fixed and you know what it is.

So, to answer your question: It's not the strange behavior of eval, it's the strange construct that you cooked. Look at the contents of the directory. If you had a file named 'break' in that dir, you'd end the loop when 'eval break' gets called.