Odd Bash script inconsistancy...

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#16 Post by seaside »

sunburnt wrote: It gives the first file... Not the wildcard argument.!!!
It seems that the wildcard is being interpreted by being the "$1" argument!
So feeding wildcards to a script just doesn`t work! Period!
Well isn't that curious!

Code: Select all

./script "t*"
WORKS

so you would think that if you build a wildcard parameter with single quotes around it - like this -

Code: Select all

# w='"t*"'
# echo $w
"t*"
# 
would do the trick - but no -

Code: Select all

./script $w or "$w"
FAILS

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#17 Post by amigo »

Enclosing in single quotes turns off expansion of wildcards -i mean the outer quotes. This: "'$var'" would still get expanded. Sometimes you have to escape characters to keep them from being immediately expanded by the shell: \$var

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#18 Post by seaside »

amigo,

Thanks for the explanation. $@ works nicely. Also found a good short description and chart of the differences between $* and $@ here -
http://fvue.nl/wiki/Bash:_Difference_between_$@_and_$*

As a general rule they suggest mostly using $@

s

Post Reply