There should be a way to disable false positives in comments, e.g.
# shellcheck disable-msg SC2086
echo $1
These should be scoped for structure for which they appear, or the entire file if at the top.
I would find this feature useful
From 43ed5e7 you can use # shellcheck disable=SC1234,SC5678. It's scoped to the immediate pipeline and any &&/|| following it.
It's worth noting that errors in a shellcheck directive (# shellcheck...) is a parsing error by design. This lets shellcheck tell you why # shellcheck ignore=1234:5678 is wrong, but also means that parsing stops if you've written # shellcheck doesn't like this.
I'd appreciate any feedback people have for this feature!
How can I disable the ps|grep warning here:
echo -n " zombie: $(ps -e -o state | grep Z | wc -l) "
# shellcheck disable=SC2009
echo -n " zombie: $(ps -e -o state | grep Z | wc -l) "
Thank you, I made a a dumb error: I had typo in the warning id, that's why it seemed not to work.
feedback is that it works great. maybe add it to the --help docs for ease of use?
It appears the directive will only apply to the line following the directive. For example:
# shellcheck disable=SC2034
AAAA=aaaa # < No 'appears unused'
BBBB=bbbb # < Getting 'appears unused' error
# shellcheck disable=SC2034
CCCC=cccc # < No 'appears unused'
DDDD=dddd # < Getting 'appears unused' error
I would expect the shellcheck directive to disable all of this error in the file, but if we need backwards compatibility, I would like a way to disable all of a specific type of error for the whole file.
My usecase: I have a dotenv file where I am declaring a lot of variables that I'm never using, because they are getting used in other files in my application. I would like to use shellcheck to syntax check the file but I don't need any 'appears unused' errors as they are irrelevant to my use.
I would strongly prefer not to have to write a shellcheck disable for each line in my file...
It's per structure, so you can do
shellcheck disable=SC2034
{
AAAA=aaaa
BBBB=bbbb
CCCC=cccc
DDDD=dddd
}
I used that method to solve my problem and it did work in my case, however I dislike the idea of having to change my code structure in order to make an ignore rule function. I would prefer to see a different directive to make all instances ignored.
Thanks for the feature though, it works great otherwise and this linter is very helpful for showing me some best-practices that I didn't know about.
Thanks, glad you like it!
In the near future you're likely to see file-wide ignores, but right now they're per structure
Understood. Thanks.
@servel333 also remember that you can disable it on the command line, might hide valid warnings in other files if you are processing more than one in a single go though. Just mentioning it as it looks like it's missing in this thread.
brother ~$ cat /tmp/test.sh
#!/bin/sh
echo "--no quote--"
for i in ${TMPDIR:=/tmp}; do echo "$i"; done
echo "------------"
echo "--- quote---"
for i in "${TMPDIR:=/tmp}"; do echo "$i"; done
echo "------------"
# shellcheck disable=SC2034
AAAA=aaaa # < No 'appears unused'
BBBB=bbbb # < Getting 'appears unused' error
# shellcheck disable=SC2034
CCCC=cccc # < No 'appears unused'
DDDD=dddd # < Getting 'appears unused' error
brother ~$ shellcheck /tmp/test.sh
In /tmp/test.sh line 8:
for i in "${TMPDIR:=/tmp}"; do echo "$i"; done
^-- SC2066: Since you double quoted this, it will not word split, and the loop will only run once.
In /tmp/test.sh line 13:
BBBB=bbbb # < Getting 'appears unused' error
^-- SC2034: BBBB appears unused. Verify it or export it.
In /tmp/test.sh line 16:
DDDD=dddd # < Getting 'appears unused' error
^-- SC2034: DDDD appears unused. Verify it or export it.
brother ~$ shellcheck /tmp/test.sh -eSC2034
In /tmp/test.sh line 8:
for i in "${TMPDIR:=/tmp}"; do echo "$i"; done
^-- SC2066: Since you double quoted this, it will not word split, and the loop will only run once.
I didn't know you could disable it in the command line like that. I'm using Sublime that's auto-running the command though and so for my use case it doesn't solve my problem. Good to know though, thanks.
If Sublime isn't configurable you can set SHELLCHECK_OPTS in recent versions of shellcheck
I actually don't want to disable this warning for all files I'm checking, just specific ones.
Most helpful comment
I actually don't want to disable this warning for all files I'm checking, just specific ones.