Timeline for Trapping errors in command substitution using "-o errtrace" (ie set -E)
Current License: CC BY-SA 3.0
24 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 8, 2021 at 22:23 | comment | added | Hiroshi_U | This is kind of side talk, but at the line "exit $?", the "$?" has already become "0" because in the one line above it was cleared. I think the question should be improved so that the value of $? should be kept in a variable before using it in this case. It's a common pitfall and it may obscure original intention of the question. | |
| Nov 7, 2018 at 18:56 | comment | added | G-Man Says 'Reinstate Monica' | Distantly related: How is the return status of a variable assignment determined? | |
| Nov 7, 2018 at 14:45 | answer | added | JigglyNaga | timeline score: 5 | |
| Nov 7, 2018 at 13:32 | comment | added | ivan_pozdeev |
@mosvy both questions are asking how to make a command line that contains $(command) fail if command fails.
|
|
| Nov 7, 2018 at 10:15 | comment | added | user313992 |
@ivan_pozdeev other than that this question contains a needless -o pipefail which "links" it to the other question, do you have any rationale to declare it a duplicate?
|
|
| Nov 7, 2018 at 0:45 | review | Close votes | |||
| Nov 7, 2018 at 10:47 | |||||
| Nov 7, 2018 at 0:25 | comment | added | ivan_pozdeev | Possible duplicate of How can I get bash to exit on backtick failure in a similar way to pipefail? | |
| S Mar 18, 2014 at 17:09 | history | bounty ended | CommunityBot | ||
| S Mar 18, 2014 at 17:09 | history | notice removed | CommunityBot | ||
| Mar 17, 2014 at 0:37 | comment | added | mikeserv | I added some stuff at the bottom. You can keep the bounty though - like I said, I don't know about bash -E. | |
| Mar 17, 2014 at 0:08 | comment | added | mikeserv |
Ok, well, I refferred to the POSIX manual, but no, you don't need another command. It will kill the shell - see the V+N? It's the only command run when it is run... Also, every time the function is called the variable is evaluated alone - the heredoc is evaluated BEFORE the function runs. I'll demonstrate.
|
|
| Mar 16, 2014 at 23:46 | answer | added | mikeserv | timeline score: 5 | |
| Mar 16, 2014 at 22:05 | comment | added | mikeserv |
You want me to answer it? But I don't know what set -E does - I don't feel competent enough in the subject material to answer it. I know how to use set -e to make it fail with or without echo, but not the way it's asked. I was just offering advice. I'll give it a go - but delete it if it sucks, ok?
|
|
| Mar 16, 2014 at 7:34 | comment | added | mikeserv | @illiminE - exactly - it's the last in the pipeline so it won't fail, but the ${var?} if unset will fail unless it is considered to be explicitly tested - according to POSIX - with [ ] || && or similar because it qualifies as a test of its own. If you add ${var?error message} you'll get "error message">&2. | |
| Mar 15, 2014 at 23:28 | comment | added | user44370 |
@mikeserv @1_CR The bash manual @echo indicates that echo always returns 0. This must be factored in the analysis...
|
|
| Mar 14, 2014 at 10:36 | answer | added | totti | timeline score: 2 | |
| Mar 12, 2014 at 10:55 | comment | added | mikeserv |
I don't know about bash's -E but I do know that -e only effects a shell exit if the error results from the last command in a pipeline. So your var=$( pipe ) and $( pipe ) examples would both represent pipe endpoints whereas pipe > echo would not. My man page says: "1. The failure of any individual command in a multi-command pipeline shall not cause the shell to exit. Only the failure of the pipeline itself shall be considered. "
|
|
| S Mar 10, 2014 at 15:51 | history | bounty started | CommunityBot | ||
| S Mar 10, 2014 at 15:51 | history | notice added | user44370 | Draw attention | |
| Sep 13, 2013 at 3:15 | history | tweeted | twitter.com/#!/StackUnix/status/378356273030627328 | ||
| Jul 2, 2013 at 18:03 | history | edited | dgo.a | CC BY-SA 3.0 |
Fixed: bug in explanation
|
| Jul 2, 2013 at 16:24 | comment | added | iruvar |
This is a good question. Replacing echo $( made up name ) with $( made up name ) produces the desired behaviour. I don't have an explanation though.
|
|
| Jul 2, 2013 at 10:12 | history | edited | dgo.a | CC BY-SA 3.0 |
Less confusion with little/big "E".
|
| Jul 2, 2013 at 10:06 | history | asked | dgo.a | CC BY-SA 3.0 |