[plug] Simple bash scripting problem

Leon Brooks leon at cyberknights.com.au
Tue Oct 11 09:02:52 WST 2005


On Monday 10 October 2005 17:49, Richard Meyer wrote:
> OK, I don't have spaces, but it IS doing the expansion in the script,
> not the command line ..

Not. Wildcarded arguments get expanded before the script is called. Your 
$1 will, however, included spaces if a wildcard included a spaced-out 
filename:

$ ls -l
total 4
-rw-rw-r--  1 lucyb users   0 Oct 11 09:00 i-do-not.file
-rw-rw-r--  1 lucyb users   0 Oct 11 09:00 i have spaces.file
-rw-rw-r--  1 lucyb users 128 Oct 11 09:01 test.sh
$ cat test.sh
#!/bin/sh
echo NAKED DOLLAR STAR
for x in $*; do
                echo [$x]
done
echo DOLLAR AT WITH QUOTES
for x in "$@"; do
                echo [$x]
done
$ sh test.sh *.file
NAKED DOLLAR STAR
[i-do-not.file]
[i]
[have]
[spaces.file]
DOLLAR AT WITH QUOTES
[i-do-not.file]
[i have spaces.file]
$

Cheers; Leon

-- 
http://cyberknights.com.au/     Modern tools; traditional dedication
http://plug.linux.org.au/       Member, Perth Linux User Group
http://slpwa.asn.au/            Member, Linux Professionals WA
http://osia.net.au/             Member, Open Source Industry Australia
http://linux.org.au/            Member, Linux Australia



More information about the plug mailing list