Timeline for Trapping errors in command substitution using "-o errtrace" (ie set -E)
Current License: CC BY-SA 3.0
33 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Mar 28, 2014 at 3:11 | comment | added | mikeserv | Good point - perhaps more effort is called for. Ill think on it. | |
| Mar 28, 2014 at 2:29 | comment | added | mikeserv | Yes, simple assignment is mentioned in the question as well as a for granted, and while i couldnt offer specific advice on how to make use of -E, i did try to show similar results to the demonstrated issue were more than possible without resorting to bashisms. In any case, it is specifically the issues you mention - like single assignment per line - that make such solutions difficult to handle in a pipeline, which i also demonstrated how to handle. Though it's true what you say - there is nothing unsafe about simply assigning it. | |
| Mar 28, 2014 at 2:17 | comment | added | user44370 |
Just v=$( madeup ). I don't see what is unsafe with that. It's just an assignment, the person mispelled the command for instance v="$(lss)". It errors. Yes you can verify with the error status of the last command $? - because it is the command on the line (an assignment with no command name) and nothing else - not an argument to echo. Plus, here it's trapped by the function as !=0, so you get feedback twice. Otherwise surely as you explain there is a better way to do this orderly within a framework but OP had 1 single line: an echo plus his failed substitution. He was wondering about echo.
|
|
| Mar 27, 2014 at 22:45 | comment | added | user44370 |
To summarize: These parameter expansions are a great way to control if variables are set etc. In respect of the exit status of echo, I noticed that echo "abc" "${v1:?}" doesn't seem to execute(abc never printed). And the shell returns 1. This is true with or without a command even("${v1:?}" directly on the cli). But for OP's script, all that was required to trigger the trap is placing his variable assignment containing a substitution for a nonexistent command alone on a single line. Otherwise the behavior of echo is to return 0 always, unless interrupted like with the tests you explained.
|
|
| Mar 27, 2014 at 6:38 | comment | added | mikeserv | For instance, practically his exact specification: echo ${v=$( madeupname )} ; echo "${v:?trap1st} ! is not reached !" | |
| Mar 27, 2014 at 0:10 | history | edited | mikeserv | CC BY-SA 3.0 |
deleted 7 characters in body; deleted 4 characters in body
|
| Mar 26, 2014 at 23:27 | history | edited | mikeserv | CC BY-SA 3.0 |
deleted 11 characters in body
|
| Mar 26, 2014 at 18:14 | history | edited | mikeserv | CC BY-SA 3.0 |
deleted 54 characters in body; deleted 8 characters in body
|
| Mar 26, 2014 at 18:07 | history | edited | mikeserv | CC BY-SA 3.0 |
added 385 characters in body; added 23 characters in body
|
| Mar 26, 2014 at 15:08 | history | edited | mikeserv | CC BY-SA 3.0 |
added 261 characters in body
|
| Mar 26, 2014 at 14:00 | history | edited | mikeserv | CC BY-SA 3.0 |
added 17 characters in body
|
| Mar 26, 2014 at 13:53 | history | edited | mikeserv | CC BY-SA 3.0 |
added 1245 characters in body
|
| Mar 17, 2014 at 23:20 | history | edited | mikeserv | CC BY-SA 3.0 |
added 1 characters in body
|
| Mar 17, 2014 at 23:06 | history | edited | mikeserv | CC BY-SA 3.0 |
added 138 characters in body
|
| Mar 17, 2014 at 22:58 | history | edited | mikeserv | CC BY-SA 3.0 |
added 138 characters in body
|
| Mar 17, 2014 at 22:45 | history | edited | mikeserv | CC BY-SA 3.0 |
deleted 16 characters in body
|
| Mar 17, 2014 at 22:35 | history | edited | mikeserv | CC BY-SA 3.0 |
deleted 16 characters in body
|
| Mar 17, 2014 at 22:24 | history | edited | mikeserv | CC BY-SA 3.0 |
edited body
|
| Mar 17, 2014 at 22:15 | history | edited | mikeserv | CC BY-SA 3.0 |
added 30 characters in body
|
| Mar 17, 2014 at 21:31 | history | edited | mikeserv | CC BY-SA 3.0 |
added 34 characters in body
|
| Mar 17, 2014 at 20:59 | history | edited | mikeserv | CC BY-SA 3.0 |
added 1607 characters in body
|
| Mar 17, 2014 at 20:51 | history | edited | mikeserv | CC BY-SA 3.0 |
added 1607 characters in body
|
| Mar 17, 2014 at 3:46 | history | edited | mikeserv | CC BY-SA 3.0 |
added 1 characters in body; Post Made Community Wiki
|
| Mar 17, 2014 at 1:20 | history | edited | mikeserv | CC BY-SA 3.0 |
added 11 characters in body
|
| Mar 17, 2014 at 1:04 | history | edited | mikeserv | CC BY-SA 3.0 |
added 6 characters in body
|
| Mar 17, 2014 at 0:54 | history | edited | mikeserv | CC BY-SA 3.0 |
added 6 characters in body
|
| Mar 17, 2014 at 0:48 | history | edited | mikeserv | CC BY-SA 3.0 |
added 1 characters in body
|
| Mar 17, 2014 at 0:41 | history | edited | mikeserv | CC BY-SA 3.0 |
deleted 1 characters in body
|
| Mar 17, 2014 at 0:29 | history | edited | mikeserv | CC BY-SA 3.0 |
added 345 characters in body
|
| Mar 17, 2014 at 0:17 | history | edited | mikeserv | CC BY-SA 3.0 |
added 345 characters in body
|
| Mar 17, 2014 at 0:00 | history | edited | mikeserv | CC BY-SA 3.0 |
added 20 characters in body
|
| Mar 16, 2014 at 23:54 | history | edited | mikeserv | CC BY-SA 3.0 |
added 469 characters in body
|
| Mar 16, 2014 at 23:46 | history | answered | mikeserv | CC BY-SA 3.0 |