You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In POSIX sh, unary -o to check options is undefined.
Problematic code:
if [ -o braceexpand ]
thenecho"Brace expansion available and enabled."fi
Correct code:
$- will be set to a list of shell options:
case$- of
*B*) echo"Brace expansion available and enabled."esac
However, not all options are available through $-. If you need to check those, ignore this suggestion with a directive:
# shellcheck disable=SC3062if [ -n"$BASH_VERSION" ] && [ -o pipefail ]
thenecho"This is bash and pipefail is enabled."fi
Rationale:
[ -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.
Exceptions:
As described.
Related resources:
Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!