Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new check: warn about using set with default values #1933

Open
1 of 2 tasks
pabs3 opened this issue May 1, 2020 · 1 comment
Open
1 of 2 tasks

new check: warn about using set with default values #1933

pabs3 opened this issue May 1, 2020 · 1 comment

Comments

@pabs3
Copy link

pabs3 commented May 1, 2020

For new checks and feature suggestions

I can't check shellcheck.net because it requires JavaScript.

Here's a snippet or screenshot that shows the problem:

#!/bin/sh
set +x
echo foo

Here's what shellcheck currently says:

Nothing

Here's what I wanted or expected to see:

You have used set +x, which is the default, did you mean set -x instead?

Comment

ShellCheck could trace all use of the set builtin and determine what the current values are and where the set commands have no effect because they either set to the default or they set to the same value as an earlier set command.

@brother
Copy link
Collaborator

brother commented May 4, 2020

As long as the current script isn't sourced into something else that could have had the default bit flipped...

brother ~$ cat /tmp/a.sh 
#!/bin/sh
echo foo
set +x
echo bar
brother ~$ cat /tmp/b.sh 
#!/bin/sh
set -x
echo sourcing
. /tmp/a.sh
echo done
brother ~$ /tmp/b.sh
+ echo sourcing
sourcing
+ . /tmp/a.sh
+ echo foo
foo
+ set +x
bar
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants