[lug] Passing multiword parameters through rsh from ksh

Hugh Brown hugh at math.byu.edu
Fri Feb 23 12:38:22 MST 2007


I'd also look at the getopts function.  I believe ksh has it builtin
(bash does).

Hugh

On Fri, 23 Feb 2007, Zan Lynx wrote:

> On Fri, 2007-02-23 at 11:18 -0700, Elyse M. Grasso wrote:
> > When I pass a parameter with blank spaces in it through rsh, it gets split
> > into separate parameters when it reaches the remote program.
> >
> > My ksh and rsh are pretty rusty. Is there a syntax for doing this?
> >
> > Does not work:
> > script.ksh 'multiword value' value2
> >
> > #!/bin/ksh
> > # check for valid params
> > rsh $HOST "progname"  "$@"
> >
> > also does not work:
> > #!/bin/ksh
> > # check for valid params
> > note=$1
> > shift
> > rsh $HOST "progname" "'$note'" "$@"
> >
> > Google is not being helpful.
>
> Just a reminder that rsh is really insecure.  It's OK if you're running
> stuff inside a cluster environment or somewhere you can really trust all
> the systems.
>
> But anyway, both rsh and ssh invoke a shell on the _remote_ computer.
> *That* shell receives the string that you sent, which was processed by
> the local shell first.
>
> That means, that you need *double* shell escaping and quoting, one for
> the local shell, one for the remote shell.
>
> So maybe:
> rsh $HOST "'progname' '$note' '$@'"
>
> Note the nesting of single quotes and double quotes.  That is untested
> but might work.
>
> A way to test your quoting is to write a script on the remote system
> that writes out command arguments as it sees them, perhaps one per line
> using a while shift loop or for i in "$@" or something similar.  Then
> you can rsh to that script to see what you get.
> --
> Zan Lynx <zlynx at acm.org>
>



More information about the LUG mailing list