Ubuntu – Can a Bash shell option be set for a single command

bashcommand line

I like the way a variable can be set for a single command, such as:

LANG=fr_FR.utf8 df -h

Is it possible to use the shopt -s command, or some other method, to set a shell option, such as nullglob or extglob, for a single command in the same manner?

Best Answer

Depending on your use case, use a subshell:

(shopt -s nullglob; foo)