Timeline for Conditional pipeline
Current License: CC BY-SA 3.0
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 15, 2020 at 11:43 | comment | added | Nick Bull |
Main takeaway is that condition && command1 || command2 is not the same as if condition; then command1; else command2; fi
|
|
| Apr 13, 2017 at 12:36 | history | edited | CommunityBot |
replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
|
|
| Dec 3, 2012 at 7:10 | comment | added | manatwork | Thank you for the explanation, @musiphil. Now I understand Jonas' argument. | |
| Dec 2, 2012 at 21:17 | comment | added | musiphil |
@manatwork: One thing Jonas is pointing out is that, in [[ "${DEFINED}" ]] && cmd3 || cat, cmd3 and cat are not the mutually exclusive then and else branches of the same if, but that if cmd3 fails, then cat will also be executed. (Of course, if cmd3 always succeeds, or if it consumes all the input so there's nothing left in stdin for cat to process, then the it may not matter.) If you need both then and else branches, it's better to use an explicit if command, not && and ||.
|
|
| May 20, 2012 at 11:29 | comment | added | manatwork |
I can't see how is this relevant here. The else (or ||) should act as a null operation keeping the input unchanged. So replacing cat with echo changes everything making your code irrelevant. Regarding the “and-false-or gotcha”, I see no interference with the pipeline: pastebin.com/u6Jq0bZe
|
|
| May 20, 2012 at 11:06 | history | answered | Jonas Kölker | CC BY-SA 3.0 |