Guys,
I'm either misunderstanding how to control expansion of wildcards on the
command line when passing the parameter containing the wildcard as a cli option
to a script or the bash controls to allow that are broken. I want to set up a
little script alias to search /var/abs for packages and I want the ability to
pass either 'name' or 'name*' or '*name*' as input, but if there is anything
matching in the current directory, expansion happens before the cli is passed to
the script.
Reading, I should be able to turn globbing off with either 'set -f' or 'set -o
noglob' and then I should be able to pass the parameter contained a wildcard to
the script without any pathname expansion. That appears broken -- or my logic is
broken.
From man bash 'set -f' or 'set -o noglob on' should prevent expansion:
set [+abefhkmnptuvxBCEHPT] [+o option] [arg ...]
<snip>
-f Disable pathname expansion.
<snip>
-o option-name
The option-name can be one of the following:
<snip>
noglob Same as -f.
EXAMPLE:
touch pacman-foo
then use the following as your test script (tst.sh):
#!/bin/bash
myvar="$1"
printf "Search: %s\n" $myvar
exit 0
Now since i have a file called pacman-foo in my directory trying to pass
'pacman*' should result in expansion before the cli is read resulting in:
00:42 nirvana:~/scr/arch/tmp> ./tst.sh pacman*
Search: pacman-foo
single-quoting doesn't even protect the cli?? :
00:42 nirvana:~/scr/arch/tmp> ./tst.sh 'pacman*'
Search: pacman-foo
Now try 'set -f' to disable pathname expanstion:
01:00 nirvana:~/scr/arch/tmp> set -f
01:02 nirvana:~/scr/arch/tmp> ./tst.sh pacman*
Search: pacman-foo
01:02 nirvana:~/scr/arch/tmp> ./tst.sh 'pacman*'
Search: pacman-foo
Huh? Now try 'set -o noglob'
01:02 nirvana:~/scr/arch/tmp> set -o noglob
01:03 nirvana:~/scr/arch/tmp> ./tst.sh pacman*
Search: pacman-foo
01:04 nirvana:~/scr/arch/tmp> ./tst.sh 'pacman*'
Search: pacman-foo
Huh? Again.. What gives is it bash or is it something I'm reading wrong?
--
David C. Rankin, J.D.,P.E.
Rankin Law Firm, PLLC
510 Ochiltree Street
Nacogdoches, Texas 75961
Telephone: (936) 715-9333
Facsimile: (936) 715-9339
www.rankinlawfirm.com