How do I turn off wildcard expansion in Unix (BASH) Shell permanently?

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?

 
Utilize the ‘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:

Advertisement

4 thoughts on “How do I turn off wildcard expansion in Unix (BASH) Shell permanently?

  1. 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.

    1. 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.