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

Gary W. Swearingen garys at opusnet.com
Mon Jul 25 14:10:17 GMT 2005


Damian Gerow <dgerow at afflictions.org> writes:

> Yeah, but...
>
> The current shell still interprets $SHELL, and assigns it whatever local
> value it has.  I don't want that.  I want $SHELL to be evaluated by the
> remote system (the on to which I am establishing the SSH connection).

No, the whole object of my examples was to pass "$SHELL" to the echo
command without interpretation by the shell -- which they did.
>
> To answer my own question: it looks like sh just isn't the right tool for
> the job.  I'm going to have to either completely change my approach to the
> problem I'm trying to solve, or use Perl and Net::SSH (and given my problem,
> I'm tending towards the latter).

Standard shells can do almost anything; just awkwardly and in
hard-to-decipher style.

This should demonstrate better.  I've got two scripts:

-- tryit:
#!/bin/sh
PROCESS=process
export PROCESS
ssh "for PROCESS in 01 02 ; do echo \${PROCESS} ; done"

-- ssh:
#!/bin/sh
PROCESS=newproc
echo "From 'ssh': '$@'"
eval "$@"

-- running tryit:
$ temptry
>From 'ssh': 'for PROCESS in 01 02 ; do echo ${PROCESS} ; done'
01
02


More information about the freebsd-questions mailing list