home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / shell / 5212 < prev    next >
Encoding:
Internet Message Format  |  1992-12-31  |  1.6 KB

  1. Path: sparky!uunet!spool.mu.edu!olivea!gossip.pyramid.com!pyramid!infmx!hartman
  2. From: hartman@informix.com (Robert Hartman)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: shell
  5. Keywords: shell
  6. Message-ID: <1992Dec31.184156.12582@informix.com>
  7. Date: 31 Dec 92 18:41:56 GMT
  8. References: <1992Dec30.150828.24430@netcom.com>
  9. Sender: news@informix.com (Usenet News)
  10. Organization: Informix Software, Inc.
  11. Lines: 35
  12.  
  13. In article <1992Dec30.150828.24430@netcom.com> kasajian@netcom.com (Kenneth Kasajian) writes:
  14. >I'd like to have a shell program (using c-shell) called "dir" that works
  15. >like ls -l -F so I created a file called dir with the exec attribute with
  16. >the following contents:
  17. >ls -l -F $1
  18. >but the $1 doesn't expand wildcards properly.  What am I doing wrong?
  19. >Kenny
  20.  
  21. Actually, $1 is behaving as expected.  Your script is performed by a
  22. subshell (child of your current shell).  Your current shell is the
  23. one that expands wild cards, and does so before starting the
  24. subshell that runs your script.  So if you have the following files
  25. in your directory:
  26.  
  27.     bar
  28.     foo
  29.  
  30. and you say:
  31.  
  32.     dir *
  33.  
  34. the script is invoked with the following arguments:
  35.  
  36.     dir bar foo
  37.  
  38. and, as you can see, bar is argument number 1.  If you run csh, you
  39. can set the echo variable to see how the shell expands wild cards.
  40.  
  41. Rather than using $1, you want to use $*, which expands to all
  42. arguments.  In sh, when you need to include white space within
  43. quoted arguments, "$@" is used in place of $*.  Chances are it will
  44. be a while before you need this, but I wanted to mention it because
  45. it was several years before I knew what "$@" was for.
  46.  
  47. -r
  48.