Above script exited after displaying the first file name.
#/bin/bash
# script m2.sh, invoked by m2.sh *.00?
MASK="$@"
for f in $MASK
do
echo $f
done
This one listed all file names.
What's wrong about using @1?
--
@~@ Might, Courage, Vision, SINCERITY.
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Ubuntu 9.04) Linux 2.6.30.1
^ ^ 18:32:02 up 4:45 0 users load average: 4.19 3.23 3.10
???! ???! ???! ???! ???! ???! ????? (CSSA):
http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa
>#/bin/bash
># script m1.sh, invoked by m1.sh *.00?
>MASK="$1"
>for f in $MASK
>do
> echo $f
>done
>Above script exited after displaying the first file name.
>#/bin/bash
># script m2.sh, invoked by m2.sh *.00?
>MASK="$@"
>for f in $MASK
>do
> echo $f
>done
>This one listed all file names.
>What's wrong about using @1?
$1 is the first argument. $@ is all the arguments from the first to the last.
It seems to be working exactly as advertised. Maybe you are getting confused with glob expansion.
That id done by the shell before the command is run. Thus
ml.sh *.00
will actually be run exactly as if you had typed in
ml.sh a.00 b.00 c.00 d.00
The first argument to ml.sh is NOT *.00, it is a.00
If you really wanted to preserver *.00 as the argument, you have to protect it
either
\*.00 or '*.00'
Thank you!
--
@~@ Might, Courage, Vision, SINCERITY.
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Ubuntu 9.04) Linux 2.6.30.1
^ ^ 21:25:01 up 7:38 0 users load average: 1.14 1.14 1.16
嚙踝蕭嚙褕貸! 嚙踝蕭嚙畿嚙瘤! 嚙踝蕭嚙踝蕭嚙踝蕭! 嚙踝蕭嚙踝蕭嚙踝蕭! 嚙踝蕭嚙踝蕭嚙確! 嚙踝蕭嚙諛梧蕭! 嚙請考慮嚙踐援 (CSSA):
http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa
But I don't understand. "*.00?" should not have been interpreted until
it reached the for-loop, shouldn't it? Are you saying it's expanded when
it's still a parameter to m1.sh?
--
@~@ Might, Courage, Vision, SINCERITY.
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Ubuntu 9.04) Linux 2.6.30.1
^ ^ 21:31:02 up 7:44 1 user load average: 1.16 1.12 1.14
The * is expanded before the script is run, bash does this for you, and all
this is done by bash, which means that your script will never see it.
--
//Aho
I think it's a bit counter-intuitive! Definitely not the case of most
programming language (like Pascal, C, .... )
So I needed to turn off globing to disable this behavior of Bash?
--
@~@ Might, Courage, Vision, SINCERITY.
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Ubuntu 9.04) Linux 2.6.30.1
^ ^ 12:06:02 up 22:19 0 users load average: 1.21 1.19 1.18
>> The * is expanded before the script is run, bash does this for you, and
>> all this is done by bash, which means that your script will never see it.
>>
>
> I think it's a bit counter-intuitive! Definitely not the case of most
> programming language (like Pascal, C, .... )
You will find bash itself is written in C. Your point?
> So I needed to turn off globing to disable this behavior of Bash?
No. Just accept it.
>> The * is expanded before the script is run, bash does this for you, and
>> all this is done by bash, which means that your script will never see it.
>>
>
> I think it's a bit counter-intuitive! Definitely not the case of most
> programming language (like Pascal, C, .... )
That's not related to any programming language, parameter are always
expanded by the calling shell. It's the way Unix shells are expected
to work.
> So I needed to turn off globing to disable this behavior of Bash?
I don't think that's possible.
Florian
--
<http://www.florian-diesch.de/>
>No. Just accept it.
Yes, just learn how shells and bash operate. YOu want globing. It was
you that used *.ll in your command. But I am sure you do not want the
file which is is called *.ll . You want something to expand it out.
Now under Microsoft, the expansion is done inside each program leading
to all sorts of inconsistancies. Under Linux/Unix, the expansion is done
before hand by the shell, meaning everything is handled in the same way.
rm *.ll does not deliver something different from ls *.ll.
Note that C does not do globing at all so your statement that C does not
do it this way, is like saying a horse does not spin its wheels like a
Ford Truck does.
Sure it is
program '*.ll" will deliver the argument *.ll to the program, not the
expanded list. So will
program \*.ll
But exactly why you would want that I have no idea.
> Florian
>--
><http://www.florian-diesch.de/>
> Florian Diesch <die...@spamfence.net> writes:
>
>>"Man-wai Chang to The Door (+MS=V32B)" <toylet...@gmail.com> wrote:
>
>>>> The * is expanded before the script is run, bash does this for you, and
>>>> all this is done by bash, which means that your script will never see it.
>>>>
>>>
>>> I think it's a bit counter-intuitive! Definitely not the case of most
>>> programming language (like Pascal, C, .... )
>
>>That's not related to any programming language, parameter are always
>>expanded by the calling shell. It's the way Unix shells are expected
>>to work.
>
>>> So I needed to turn off globing to disable this behavior of Bash?
>
>>I don't think that's possible.
>
> Sure it is
> program '*.ll" will deliver the argument *.ll to the program, not the
> expanded list. So will
> program \*.ll
Sure, but AFAIK there's no way to tell bash not to expand a bare *
without any escaping or quoting.
Florian
--
<http://www.florian-diesch.de/>
>Unruh <unruh...@physics.ubc.ca> wrote:
opal[unruh]>bash -f
opan[unruh]>ls *
/bin/ls: cannot access *: No such file or directory
Thanks, didn't know that.
Florian
--
<http://www.florian-diesch.de/>
I am trying to write a script that does a sanity check before it
performs an rm on file globs. If i could get the string with the glob
characters in tact, then I could do my sanity check on a string of not
more than 100-200 characters. If I can not turn this globbing function
off temporarily, then the number of files could be in the 1000's
theoretically. So this function requires double execution time.
Maybe it doesn't matter. rm is one of the fastest commands in the
repertoire.
There is also a matter of consistency. If bash can find files to glob
it treats the characters as special characters, and performs the glob.
If it can not do a glob in the directory, it considers the glob
characters as ordinary characters and you can see the characters in the
string that gets passed to the script.
I guess this behavior is probably best explained by the glob happening
at the first possible opportunity, but still confusing if you expect
this behavior.
--
beaminup