Search code examples
bashwildcardglobwildcard-expansionfile-globs

Stop shell wildcard character expansion?


Is there any way for a compiled command-line program to tell bash or csh that it does not want any wildcard characters in its parameters expanded?

For instance, one might want a shell command like:

foo *

to simply return the numeric ASCII value of that character.


Solution

  • No. The expansion takes place before the command is actually run.
    You can only disable the glob before running the command or by quoting the star.

    $ # quote it
    $ foo '*'
    
    $ # or escape it
    $ foo \*
    
    $ # or disable the glob (noglob)
    $ set -f
    $ foo *
    
    $ # alternative to set -f
    $ set -o noglob
    $ # undo it by 
    $ set +o noglob