Getting return value in os.system rsh call
A. Lloyd Flanagan
alloydflanagan at attbi.com
Thu Jan 30 20:14:13 CET 2003
migmog99 at hotmail.com (Andrew) wrote in message news:<48633651.0301300317.174e5e1b at posting.google.com>...
> ... I need the slash. Then it works. The thing is I've never been
> completely happy with my understanding of Unix quoting.
> Can anyone explain why putting the slash in makes a difference?
> 11:13:23$ rsh -n remote "./bad.py; echo $?; hostname"
It's a little confusing because you're dealing with two command
interpreters: the one you type the command into, and the one running
on the remote machine that executes your string.
Because your string is enclosed in double quotes, not single quotes,
the shell you type the command into is going to expand $?. What the
remote machine sees is actually
./bad.py; echo 0; hostname
The \ (backslash) before the $ prevents the local shell from expanding
$?, so rsh gets
./bad.py; echo $?; hostname
and then the $? gets expanded by the remote shell.
Another way to prevent expansion of the $? construct is to enclose the
string in single quotes, like:
> 11:13:23$ rsh -n remote './bad.py; echo $?; hostname'
Single quotes prevent expansion of shell variables inside them.
More information about the Python-list