4

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:

not/*/expanded
neither should this/be/expanded?
accepted too*

1 Answer 1

6

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

and

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .