Connor Connor - 2 months ago 20
Bash Question

shopt -q in terminal no return

Going through the Bash reference guide, trying to understand nullglob and bash in general. But when I try:

$shopt -q nullglob

I get no return. If nullglob is off, shouldn't I get a 0 return? I don't understand -q option

Answer Source

From the description of the -q option in the Bash

Suppresses normal output; the return status indicates whether the optname is set or unset.

The variable $? contains the status of the last command.

shopt -q nullglob
echo $?

That will print 0 if it's set, 1 if it's not set.

But it's more useful in an if:

if shopt -q nullglob
then echo nullglob is set
else echo nullglob is not set