On Wed, Dec 28, 2005 at 02:13:44PM -0500, Yaroslav Halchenko wrote:
|| Thank you Vincent,
||
|| But I am still wondering...
||
|| > So it runs the command /bin/echo with $1=1111. However, /bin/echo
|| > doesn't use $1, and only prints an empty line which you see.
|| so you mean that in case
|| *> rsh localhost /bin/sh -c 'hostname -i'
|| ravana
||
|| hostname doesn't have really *argv == "-i" but rather environment variable
|| $1 is set to "-i", that is why hostname just provides me with a hostname.
|| Did I understand you correctly?
In this case, hostname would not be getting the -i argument. What does
happen to the -i is a bit unclear. As it stands, I suspect it will be
interpreted as the "interactive" option to /bin/sh.[1]
|| What is then proper way to run remote complex command ("bla1 -i; bla2 -k")
|| or "pipe" via ssh/rsh? It seems that I need a bit of tutorial after all the
|| years :-)
Pass only a single command argument to rsh/ssh:
rsh localhost '/bin/sh -c "hostname -i"'
This is a single string, but with "" embedded, so the remote $SHELL
combines hostname and -i into one string.
On Wed, Dec 28, 2005 at 08:40:41PM +0100, Frank K?ster wrote:
|| vzweije@sense.xs4all.nl (Vincent Zweije) wrote:
||
|| > It's not a bug. It's a feature. :)
|| >
|| [...]
|| > /bin/sh -c '/bin/echo' '1111'
|| > /bin/tcsh -c '/bin/echo' '1111'
|| > /bin/tcsh -c '/bin/echo' '1111'
These shells read their commands from the -c argument. There's nothing
more in there than /bin/echo. If there is a $1 in there, the shell will
substitute 1111 for it.[1]
|| > So it runs the command /bin/echo with $1=1111. However, /bin/echo
|| > doesn't use $1, and only prints an empty line which you see.
||
|| Aha. So what does echo use? When I type "/bin/echo foo bar" at the
|| prompt, it's also the shell that hands over the line to echo, and it
|| does that after splitting the lines into words - so where is the
|| difference? (I see it, it's on my screen, but why?)
When you type "/bin/echo foo bar", your shell reads a command from the
line you type. The arguments foo and bar are in there.
Ciao. Vincent.
[1] I may be mistaken. If I read the shell's (well, bash') manual
correctly, the 1111 is actually the first non-option argument,
which means the shell should be interpreting it as a script to read
and execute. However, it's already reading commands from the -c
argument, so I'm getting confused. It seems some shells are getting
confused too. Whatever. It's not an echo argument.
--
Vincent Zweije <zweije@xs4all.nl> | "If you're flamed in a group you
<http://www.xs4all.nl/~zweije/> | don't read, does anybody get burnt?"
[Xhost should be taken out and shot] | -- Paul Tomblin on a.s.r.
Attachment:
signature.asc
Description: Digital signature