home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!cs.utexas.edu!uwm.edu!daffy!uwvax!ssec.wisc.edu!dws
- From: dws@ssec.wisc.edu (DaviD W. Sanderson)
- Subject: Re: rsh terminates while loop
- Message-ID: <1992Dec16.190654.2862@cs.wisc.edu>
- Sender: news@cs.wisc.edu (The News)
- Organization: UW-Madison Space Science and Engineering Center
- References: <1992Dec14.202147.5077@crd.ge.com> <1992Dec15.054605.6780@cs.wisc.edu> <1992Dec16.163349.16919@crd.ge.com>
- Date: Wed, 16 Dec 1992 19:06:54 GMT
- Lines: 46
-
- In article <1992Dec16.163349.16919@crd.ge.com> davidsen@crd.ge.com (bill davidsen) writes:
- >However, it seems that what I tried was:
- > result=`rsh $host uname $flags` < /dev/null
- >rather than
- > result=`rsh $host uname $flags < /dev/null`
- >which works.
- >
- >This is somewhat non-intuitive,
- ...
- >it's clear that redirection within the quotes will protably work,
- >even if it's not as clear that redirection outside the quotes doesn't.
-
- Let me explain.
-
- The shell (sh/ksh anyway) expands command substitutions in a 'simple
- command' (to use the man page terminology) prior to executing the
- resulting 'simple command' or processing its i/o redirections. This
- makes sense, because if i/o redirections for a 'simple command' ALSO
- applied to its command substitutions then
-
- ls -l `echo *.c` > foo
-
- would redirect the result of the 'echo *.c' into the file 'foo' instead
- of making the result of the echo part of the 'ls' command line. The
- shell would then run the 'ls -l' command with no additional arguments,
- also with its output redirected to the file 'foo'. Fortunately, this
- is NOT what the shell actually does.
-
- So, to return to the rsh example, in the command
-
- result=`rsh $host uname $flags` < /dev/null
-
- the redirection applies to the 'simple command' (which in this
- particular case happens to be an assignment), not the rsh. When the
- shell executes the rsh it has not yet processed the redirection. Since
- assignments neither read nor write any file descriptors, the i/o
- redirection for the assignment happens to have no effect on the
- assignment itself. On the other hand, in the command
-
- result=`rsh $host uname $flags < /dev/null`
-
- the redirection is part of the command the shell executes when it
- expands the command substitution in the assignment 'simple command', so
- the redirection DOES apply to the rsh in this case.
-
- DaviD W. Sanderson (dws@ssec.wisc.edu)
-