|
Home > Archive > Unix Shell > May 2004 > * in positional argument
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
* in positional argument
|
|
| beliavsky@aol.com 2004-05-10, 5:44 pm |
| Using the bash shell,
ls -rS -l *.f
lists the *.f files in order of ascending size. If I have a batch file
'lss' with the line
ls -rS -l $1
then
lss *.f
does not give the same output as the first command above -- it just
lists one file. Could someone please explain this behavior and show me
how to fix my script? Thanks.
| |
| Chris F.A. Johnson 2004-05-10, 5:44 pm |
| On 2004-05-09, beliavsky@aol.com wrote:
> Using the bash shell,
>
> ls -rS -l *.f
>
> lists the *.f files in order of ascending size. If I have a batch file
[It's called a script]
> 'lss' with the line
>
> ls -rS -l $1
>
> then
>
> lss *.f
>
> does not give the same output as the first command above -- it just
> lists one file. Could someone please explain this behavior and show me
> how to fix my script? Thanks.
Your script does not see the wildcard; the shell expands it before
passing it to your script.
Add this line to your script to see what is happening:
printf "%s\n" "$@"
Your script should use:
ls -rS -l "$@"
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
| |
| Barry Margolin 2004-05-10, 5:44 pm |
| In article <3064b51d.0405091439.45f008e4@posting.google.com>,
beliavsky@aol.com wrote:
> Using the bash shell,
>
> ls -rS -l *.f
>
> lists the *.f files in order of ascending size. If I have a batch file
> 'lss' with the line
>
> ls -rS -l $1
>
> then
>
> lss *.f
>
> does not give the same output as the first command above -- it just
> lists one file. Could someone please explain this behavior and show me
> how to fix my script? Thanks.
The shell in which you type "lss *.f" expands the wildcard, so it's as
if you had typed:
lss file1.f file2.f file3.f
$1 is replaced by the first argument to the script, which is file1.f.
If you want to substitute all the script's arguments, use:
ls -rS -l "$@"
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
| |
| Joe Davison 2004-05-20, 5:37 pm |
| On Sun, 09 May 2004, Barry Margolin wrote:
> In article <3064b51d.0405091439.45f008e4@posting.google.com>,
> beliavsky@aol.com wrote:
>
>
> The shell in which you type "lss *.f" expands the wildcard, so it's
> as if you had typed:
>
> lss file1.f file2.f file3.f
>
> $1 is replaced by the first argument to the script, which is file1.f.
>
> If you want to substitute all the script's arguments, use:
>
> ls -rS -l "$@"
Or, if you want the script to see the *.f, put it in single quotes on
the command line:
lss '*.f'
That will keep the shell from expanding it before calling lss.
joe
|
|
|
|
|