Suppose I'm a lazy bum and want to avoid putting every string in quotes when passing arguments to a function, how do I avoid the characters * and ? being used by bash for patname expansion?

Simplified example:

fn () {
    echo "$1"
# shopt -s option - disable * and ?
fn not/*/expanded
fn neither\ should\ this/be/expanded?
fn 'accepted too*'
# shopt -u option - enable * and ?

This should output:

neither should this/be/expanded?
accepted too*

The option you arer looking for is noglob and should be set using the shell built-in set.

To enable it:

set -o noglob

To disable it:

set +o noglob

Or also with set -f and set +f.

Yet another method:

shopt -os noglob


shopt -ou noglob
  • It's not a shopt (shell option) but just an "option". Thanks for putting me on the right track. – Lekensteyn May 7 '11 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.