Have you ever been annoyed by the the auto expansion of wildcards by Shell?
The wildcard expansion is a fantastic feature, but sometimes it turns out to be very pesky especially when shell expands the wildcards in an argument passed to some other program and your requirement was not to expand the them.
When we ask a Linux/UNIX user on how to turn off the ‘wildcard’ expansion in BASH Shell, an immediate reply would be use single quotes.
Are there any facilities provided by BASH Shell to turn off wildcard expansion permanently?
‘noglobe’
option. To set the ‘noglobe’
option, please execute the below command at the BASH shell:bash-prompt#>set -o noglobe;
More often, the requirement is to turn off Path name expansion. This is especially useful if a wildcard is part of an argument to a program.
Use set –f
in such cases. Execute ‘set –f
’ as below
bash-prompt#>set –f;
To reset the wildcard expansion property of the BASH Shell, execute ‘set +f
’.
Resources:
I use a combo like this to temporarily disable globbing. I define the alias in my .bashrc file.
alias qcp=’set -o noglob;myqcp’;myqcp(){ ~/scripts/qcp “$@”;set +o noglob;}
Where qcp is the command, ~/scripts/qcp is the bash script that I run with unexpanded parameters, and it enables globbing again within the function myqcp.
Please, what’s exactly the difference between “set -o noglobe” and “set -f”?
Hello Hibou57,
Thank you for sharing your thought. In some cases, ‘set -f’ is an alternative to the ‘noglobe’ option.
In some cases where ‘nogloble’ option is not available, ‘set -f’ should do the trick.
Thanks,
-Santhosh.