shellcheck: detect unbracketed if expressions in shell scripts
Fail if `if $` or `if "$` appears in a shell script, since `if [ $` may
have been intended and the test will always return false if so.
This will generate false positives if a command is being run indirectly
via a shell variable.
@@ -27,6 +27,10 @@ if [[ ${HASSHELLCHECK} == 1 ]]; then
if [[ $shebang =~ ^#!/.*/bash.* ]] || [[ $shebang =~ ^#!/.*/env\ bash ]]; then
shellcheck -x "$f"
bash -n "$f"
+ if grep -E '(^|[[:space:]])if[[:space:]]+"?\$' "$f"; then
+ echo "Possible unbracketed conditional in $f"
+ exit 1
+ fi
echo "OK ${f}"
fi
fi
