home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!olivea!gossip.pyramid.com!pyramid!infmx!hartman
- From: hartman@informix.com (Robert Hartman)
- Newsgroups: comp.unix.shell
- Subject: Re: shell
- Keywords: shell
- Message-ID: <1992Dec31.184156.12582@informix.com>
- Date: 31 Dec 92 18:41:56 GMT
- References: <1992Dec30.150828.24430@netcom.com>
- Sender: news@informix.com (Usenet News)
- Organization: Informix Software, Inc.
- Lines: 35
-
- In article <1992Dec30.150828.24430@netcom.com> kasajian@netcom.com (Kenneth Kasajian) writes:
- >I'd like to have a shell program (using c-shell) called "dir" that works
- >like ls -l -F so I created a file called dir with the exec attribute with
- >the following contents:
- >ls -l -F $1
- >but the $1 doesn't expand wildcards properly. What am I doing wrong?
- >Kenny
-
- Actually, $1 is behaving as expected. Your script is performed by a
- subshell (child of your current shell). Your current shell is the
- one that expands wild cards, and does so before starting the
- subshell that runs your script. So if you have the following files
- in your directory:
-
- bar
- foo
-
- and you say:
-
- dir *
-
- the script is invoked with the following arguments:
-
- dir bar foo
-
- and, as you can see, bar is argument number 1. If you run csh, you
- can set the echo variable to see how the shell expands wild cards.
-
- Rather than using $1, you want to use $*, which expands to all
- arguments. In sh, when you need to include white space within
- quoted arguments, "$@" is used in place of $*. Chances are it will
- be a while before you need this, but I wanted to mention it because
- it was several years before I knew what "$@" was for.
-
- -r
-