Timeline for Compatibility scripting: Save $? for use later
Current License: CC BY-SA 3.0
25 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 23, 2015 at 21:09 | answer | added | G-Man Says 'Reinstate Monica' | timeline score: 0 | |
| Jan 20, 2015 at 15:35 | comment | added | Stéphane Chazelas | See also: unix.stackexchange.com/q/99112 | |
| Jan 18, 2015 at 20:23 | vote | accept | Ole Tange | ||
| Jan 17, 2015 at 1:12 | comment | added | Barmar | I don't have an answer. I'm not sure I even understand the context. I don't know GNU Parallel. | |
| Jan 17, 2015 at 1:08 | comment | added | Ole Tange | @Barmar Show me how you would do it: Post an answer. It needs to work just as well as the perl answer. | |
| Jan 16, 2015 at 21:46 | history | edited | Ole Tange | CC BY-SA 3.0 |
added 72 characters in body
|
| Jan 16, 2015 at 21:45 | comment | added | Barmar |
Why can't you use the user's shell to execute the command they give, but bash (or whatever shell you prefer) to execute the wrapper?
|
|
| Jan 16, 2015 at 21:41 | comment | added | Ole Tange | @Barmar ... which is the reason this question is here. Given the syntaxes are incompatible, how do you achieve the effect. See a working solution below. | |
| Jan 16, 2015 at 20:36 | comment | added | Barmar |
You can't generally use the same code in both sh-like shells and csh-like shells. Their syntaxes for variable assignment and conditionals are totally incompatible.
|
|
| Jan 16, 2015 at 20:32 | comment | added | Ole Tange | @Barmar Because it is not a script: It is part of a script where the user decides the shell. So before _EXIT=$? there are commands written by the user in the user's shell. | |
| Jan 16, 2015 at 19:47 | comment | added | Barmar | Why does the shell that the user's command runs in affect the shell that you write YOUR script in? | |
| Jan 16, 2015 at 10:01 | history | edited | Ole Tange | CC BY-SA 3.0 |
Background
|
| Jan 16, 2015 at 4:57 | history | tweeted | twitter.com/#!/StackUnix/status/555951924869349376 | ||
| Jan 16, 2015 at 1:01 | history | edited | Ole Tange | CC BY-SA 3.0 |
Trying to rephrase the problem, so it is clear what the problem to be solved is.
|
| Jan 16, 2015 at 0:55 | comment | added | Martin Tournoij | So, what are you trying to do? This sounds like a case of the XY problem; perhaps with a description of your goal someone can find a solution (what you want to do there is nigh-impossible). | |
| Jan 16, 2015 at 0:41 | comment | added | Ole Tange | @Scott Ahh... but that is the goal. | |
| Jan 16, 2015 at 0:31 | comment | added | Scott - Слава Україні | @OleTange: My point was that, by including the "other code" in the parentheses, you are preventing it from having an effect on the main shell process. | |
| Jan 16, 2015 at 0:30 | answer | added | Ole Tange | timeline score: 0 | |
| Jan 16, 2015 at 0:28 | comment | added | Ole Tange | @Carpetsmoker Because the user of this code decides which shell I must use, and I do not know beforehand. | |
| Jan 16, 2015 at 0:27 | comment | added | Ole Tange | @Scott That will not work in csh. | |
| Jan 16, 2015 at 0:02 | comment | added | Scott - Слава Україні |
I'm not crystal clear on what the goal is. As a general construct, you might be better with _EXIT=$?; <<other code here>>; (exit $_EXIT), to allow the "other code" to modify the state of the shell (e.g., cd, set variables, etc.)
|
|
| Jan 15, 2015 at 23:59 | comment | added | Martin Tournoij |
You forgot fish :-) ... The problem is that variable assignment is different for sh/csh/fish, and it's not easy to make this compatible (using test or any other commands will never work, since that will reset $?)... I'm not sure what you're trying to do here, why don't you just execute your script with /bin/sh or whatever? ... The only option is to create separate scrips.
|
|
| S Jan 15, 2015 at 23:35 | history | suggested | Cyrus |
tag zsh added
|
|
| Jan 15, 2015 at 23:27 | review | Suggested edits | |||
| S Jan 15, 2015 at 23:35 | |||||
| Jan 15, 2015 at 23:24 | history | asked | Ole Tange | CC BY-SA 3.0 |