- Notifications
You must be signed in to change notification settings - Fork1.9k
add check for set e and operator#2237
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Conversation
koalaman commentedJul 19, 2021
Part of what it does is to forego exiting when a failing command is used as a condition, such as with Is the expectation that the user will rewrite AND-lists into |
jchorl commentedJul 20, 2021
Thanks for the response! Agreed that
I could think of a couple remediations given this warning:
If we wanted to make this more user friendly, we couldnot warn if the line ends with I'm not particularly tied to any specific implementation - just feel that there is an opportunity here to help users avoid a footgun. However we go about that is 👍 |
koalaman commentedJul 22, 2021
If the
then suggest rewriting it via Obviously this increases the complexity a bit and is not fair to ask of this small PR, but let me know if you'd still like to give it a whack. All the information can be deduced from walking the list of parent elements ( |
jchorl commentedJul 22, 2021
I'm on vacation, might as well mess around with haskell. I'll take a stab at it over the next week and see what happens. |
uri-canva commentedAug 20, 2021
This check would be quite useful, the more I thought about it the more confused I got, so I tested out the whole truth table of common logical operators: evaluate_boolean() {local expression="$1"local output output=$(bash -c"set -e;$expression; echo end")local rceval"$expression" rc=$?if [["$output"=="end" ]];thenecho"$expression returns${rc} and continues"elseecho"$expression returns${rc} and exits"fi}whileread -r expression;do evaluate_boolean"$expression"done<<EOFfalse && truefalse || truetrue && falsetrue || falsetrue && truetrue || truefalse && falsefalse || false! true! falsetruefalseEOF false && true returns 1 and continuesfalse || true returns 0 and continuestrue && false returns 1 and exitstrue || false returns 0 and continuestrue && true returns 0 and continuestrue || true returns 0 and continuesfalse && false returns 1 and continuesfalse || false returns 1 and exits! true returns 1 and continues! false returns 0 and continuestrue returns 0 and continuesfalse returns 1 and exits With My highlight is These results are very confusing so I'd love my script to have some bug I've missed, but I've tested the most egregious results in a plain shell and could reproduce them. |
uri-canva commentedAug 20, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The documentation for |
50074dc toeac8effCompare
Add a new rule to check for
&&usage withset -eset.Recently I got burned byhttps://unix.stackexchange.com/questions/312631/bash-script-with-set-e-doesnt-stop-on-command/318412#318412
I'm pretty new to Haskell so I figured I'd start small. In the future, we could expand this to include
if,while,||, etc.While this rule is very broad-reaching, I believe it to be helpful.
Looking for advice on:
infoon?For some backstory on why this is useful:
I had a script like:
This actually prints
command exited 1, while I'd expect it to not even make it to theecho.The following script doesnot make it to the echo:
To me this was extremely unintuitive and I wish shellcheck would have warned me.