home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / question / 10093 < prev    next >
Encoding:
Text File  |  1992-08-14  |  1.6 KB  |  46 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!elroy.jpl.nasa.gov!usc!sol.ctr.columbia.edu!destroyer!ubc-cs!alberta!kakwa.ucs.ualberta.ca!acs.ucalgary.ca!iwsbarke
  3. From: iwsbarke@acs.ucalgary.ca (I W Scott Barker)
  4. Subject: Re: why use eval?
  5. Sender: news@acs.ucalgary.ca (USENET News System)
  6. Message-ID: <92Aug14.215513.11933@acs.ucalgary.ca>
  7. Date: Fri, 14 Aug 92 21:55:13 GMT
  8. References: <92Aug14.195242.10973@acs.ucalgary.ca>
  9. Nntp-Posting-Host: acs5.acs.ucalgary.ca
  10. Organization: The University of Calgary, Alberta, Canada
  11. X-Newsreader: Tin 1.1 PL5
  12. Lines: 32
  13.  
  14. > What is the significance of using eval `[command]`? The man pages state that
  15. > this runs the command [command] in the shell. Does not simply typing the
  16. > command alone accomplish the same thing?
  17.  
  18. I believe I have figured out the use of eval. The back-quotes around a command
  19. cause that command to be executed in a sub-shell, after command/filename/
  20. variable substitution, and the resulting output is passed back to the shell as
  21. text. No further substitution is performed on that text. If, however, the
  22. back-quoted command is an argument to eval, substition IS performed on the
  23. resulting text. Thus, for example:
  24.  
  25. alias ls 'ls -Fa'
  26. set foo=ls
  27. `echo $foo`
  28.  
  29. results in a "simple" ls being performed, while
  30.  
  31. alias ls 'ls -Fa'
  32. set foo=ls
  33. eval `echo $foo`
  34.  
  35. results in an ls -Fa being performed, since eval caused further command
  36. substition to be performed.
  37.  
  38. Is this correct?
  39.  
  40. --
  41. Scott Barker
  42. barker@enel.ucalgary.ca
  43.  
  44. "Remember, wherever you go, there you are."
  45.    - Peter Weller, The Adventures of Buckaroo Banzai Across the 8th Dimension!
  46.