if [ -o braceexpand ]
then
echo "Brace expansion available and enabled."
fi
$-
will be set to a list of shell options:
case $- of
"Brace expansion available and enabled."
*B*) echo esac
However, not all options are available through $-
. If
you need to check those, ignore this suggestion with a directive:
# shellcheck disable=SC3062
if [ -n "$BASH_VERSION" ] && [ -o pipefail ]
then
echo "This is bash and pipefail is enabled."
fi
[ -o option ]
is a bash/ksh extension, while
$-
is standard POSIX. Do note that letters outside the
POSIX set are not guaranteed to be compatible, such as B
above.
As described.
ShellCheck is a static analysis tool for shell scripts. This page is part of its documentation.