Stop shell wildcard character expansion?

hotpaw2 picture hotpaw2 · Jul 12, 2012 · Viewed 65.2k times · Source

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.

Answer

c00kiemon5ter picture c00kiemon5ter · Jul 12, 2012

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