Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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*
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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