anordal / shellharden

The corrective bash syntax highlighter
Mozilla Public License 2.0
4.62k stars 129 forks source link

Incorrect assumption at how_to_do_things_safely_in_bash.md +320 #24

Closed mrinaldhillon closed 5 years ago

mrinaldhillon commented 5 years ago

Following seems incorrect since command's return value is overwritten by if statement. if ! command; then echo "Command returned $?" fi

Use following instead: command || echo "Command returned $?"

anordal commented 5 years ago

Well spotted sir!

I think the negation is enough to explain this:

> ! bash -c "exit 42"
> echo "$?"
0