Shell scripts, SSH sessions, and for loops, oh my!

Gary W. Swearingen garys at opusnet.com
Mon Jul 25 05:47:47 GMT 2005


Damian Gerow <dgerow at afflictions.org> writes:

> I'm trying to write a shell script that runs a for loop in an SSH session.
> Simply, I'm trying to do this:
>
>     for HOST in `cat hostnames` ; do
> 	ssh ${HOST} "for PROCESS in 01 02 ; do echo '${PROCESS}' ; done"
>     done
>
> But because this is run in a script, that gets translated to:
>
>     for HOST in `cat hostnames` ; do
> 	ssh ${HOST} "for PROCESS in 01 02 ; do echo '' ; done"
>     done

Here's a few clues (assuming you really want the single quotes in there):

echo "THIS is SHELL: '\$SHELL'"
echo "THIS is SHELL: '"'$SHELL'"'"
echo 'THIS is SHELL: '\''$SHELL'\'

which all give

THIS is SHELL: '$SHELL'


More information about the freebsd-questions mailing list