home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / unix / shell / 5090 < prev    next >
Encoding:
Text File  |  1992-12-16  |  2.3 KB  |  58 lines

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!cs.utexas.edu!uwm.edu!daffy!uwvax!ssec.wisc.edu!dws
  3. From: dws@ssec.wisc.edu (DaviD W. Sanderson)
  4. Subject: Re: rsh terminates while loop
  5. Message-ID: <1992Dec16.190654.2862@cs.wisc.edu>
  6. Sender: news@cs.wisc.edu (The News)
  7. Organization: UW-Madison Space Science and Engineering Center
  8. References: <1992Dec14.202147.5077@crd.ge.com> <1992Dec15.054605.6780@cs.wisc.edu> <1992Dec16.163349.16919@crd.ge.com>
  9. Date: Wed, 16 Dec 1992 19:06:54 GMT
  10. Lines: 46
  11.  
  12. In article <1992Dec16.163349.16919@crd.ge.com> davidsen@crd.ge.com (bill davidsen) writes:
  13. >However, it seems that what I tried was:
  14. >  result=`rsh $host uname $flags` < /dev/null
  15. >rather than
  16. >  result=`rsh $host uname $flags < /dev/null`
  17. >which works.
  18. >
  19. >This is somewhat non-intuitive,
  20. ...
  21. >it's clear that redirection within the quotes will protably work,
  22. >even if it's not as clear that redirection outside the quotes doesn't.
  23.  
  24. Let me explain.
  25.  
  26. The shell (sh/ksh anyway) expands command substitutions in a 'simple
  27. command' (to use the man page terminology) prior to executing the
  28. resulting 'simple command' or processing its i/o redirections.  This
  29. makes sense, because if i/o redirections for a 'simple command' ALSO
  30. applied to its command substitutions then
  31.  
  32.     ls -l `echo *.c` > foo
  33.  
  34. would redirect the result of the 'echo *.c' into the file 'foo' instead
  35. of making the result of the echo part of the 'ls' command line.  The
  36. shell would then run the 'ls -l' command with no additional arguments,
  37. also with its output redirected to the file 'foo'.  Fortunately, this
  38. is NOT what the shell actually does.
  39.  
  40. So, to return to the rsh example, in the command
  41.  
  42.     result=`rsh $host uname $flags` < /dev/null
  43.  
  44. the redirection applies to the 'simple command' (which in this
  45. particular case happens to be an assignment), not the rsh.  When the
  46. shell executes the rsh it has not yet processed the redirection.  Since
  47. assignments neither read nor write any file descriptors, the i/o
  48. redirection for the assignment happens to have no effect on the
  49. assignment itself.  On the other hand, in the command
  50.  
  51.     result=`rsh $host uname $flags < /dev/null`
  52.  
  53. the redirection is part of the command the shell executes when it
  54. expands the command substitution in the assignment 'simple command', so
  55. the redirection DOES apply to the rsh in this case.
  56.  
  57. DaviD W. Sanderson (dws@ssec.wisc.edu)
  58.