shellcheck
shellcheck copied to clipboard
style: warn about using "shell keywords" or "builtins"
like warning about using keyword 'do' without quotation marks e.g.
x() {
local arg="$1"
echo "$arg"
}
x do
x "do"
x if
x "if"
keywords are e.g.:
user@bashbox:~$ compgen -k
if
then
else
elif
fi
case
esac
for
select
while
until
do
done
in
function
time
{
}
!
[[
]]
coproc
I'm just another user of ShellCheck, but I don't see what the problem is. At least in Bash, pasting that example code into a new script echoes "do" and "if" twice each, exactly as expected. Does it behave differently in another shell?
Edit: I see an inconsistency when I run ShellCheck on this. It gives a warning for "Use semicolon or linefeed before 'do' (or quote to make it literal)." but doesn't say anything about "if". Although I don't think a keyword should necessarily be checked when used in the context of an argument to a command/function, any such checking should at least be consistent across keywords.
OP here: ofcourse the code works, but IMHO it's bad style, e.g. it breaks the syntax highlightning and should just be avoided.
ShellCheck currently warns about some mid- and end tokens like do/done/fi/esac because it's not at all obvious that the "then" and "fi" are literal in if true then true fi
There's no warning for start tokens, since it's more obvious that echo if true isn't a proper if statement.
I definitely agree that it's bad style, and there should be an optional warning about it.
IMHO it's bad style
In mine, its fine
it breaks the syntax highlightning
Then your syntax highlighter is incorrect. There is no "the" syntax highlighter.
Why is this issue open after 7 years?
Why is this issue open after 7 years?
I would assume it's because @koalaman stated "I definitely agree that it's bad style, and there should be an optional warning about it." and no one have yet fixed that?