Timeline for Why is pattern "command || true" useful?
Current License: CC BY-SA 3.0
9 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 25, 2016 at 2:04 | comment | added | Stack Exchange Broke The Law |
@MichaelFelt Consider: git remote remove foo || true git remote add foo http://blah - we want to ignore the error if the remote doesn't exist.
|
|
| Nov 24, 2016 at 16:53 | comment | added | Michael Felt |
what I have to ask myself is: is || true - a coding crutch (lazy way to get around/past an error I do not want to deal with now; a debug tool (-e but no || true) or just someone's dogma about what good coding practice is. In other words - I see it as a feature - with potential benefit. I do not see it as a magic wand to cure all. In short - just as beauty is in the eye of the beholder - set -e and || true utility will be defined by the traits and goals of the programmer.
|
|
| Nov 24, 2016 at 16:48 | comment | added | Michael Felt | I am a simple person - and for me the only reason to mask the error status is because it is "in the way". set -e makes any error "in the way" if before you did not care. I like the discussion because I see it as a nice way to help me debug my scripts and write additional logic to respond to an error (e.g., || print -- "xxx existed non-zero here". More likely though I have a shell function 'fatal' and I have "something || fatal "unhappy me". imho a script should report a failed status, or not care. -e plus || true is masking errors. If that is what I want - fine, if not, I am missing errors | |
| Nov 24, 2016 at 16:33 | comment | added | rackandboneman | set -e means that the script will instantly terminate upon a non-zero return. You might, in that localized spot, not want that happening! | |
| Nov 24, 2016 at 16:05 | history | edited | muru | CC BY-SA 3.0 |
deleted 13 characters in body
|
| Nov 24, 2016 at 15:47 | comment | added | moopet | That's true, but it doesn't answer why masking a command's exit status is useful. | |
| Nov 24, 2016 at 12:25 | review | Suggested edits | |||
| Nov 24, 2016 at 13:38 | |||||
| Nov 24, 2016 at 11:33 | vote | accept | carpenter | ||
| Nov 25, 2016 at 11:51 | |||||
| Nov 24, 2016 at 11:19 | history | answered | Michael Felt | CC BY-SA 3.0 |