Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

15
  • 1
    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. Commented Jan 15, 2015 at 23:59
  • 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.) Commented Jan 16, 2015 at 0:02
  • @Scott That will not work in csh. Commented Jan 16, 2015 at 0:27
  • @Carpetsmoker Because the user of this code decides which shell I must use, and I do not know beforehand. Commented Jan 16, 2015 at 0:28
  • 1
    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. Commented Jan 16, 2015 at 20:36