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.

6
  • I missed the $0 part, thanks! Much appreciate it. Now how would one format this if the path to some_program was also stored in a variable (say $cmd)? Also, you're correct about the login shell part... that's not actually necessary. Commented Aug 21, 2012 at 17:28
  • @JCOidl bash -c '"$@"' _ "$cmd" "$@" though if you don't need the login shell, then you don't need to invoke a new instance of bash either, just run it in the current script. "$cmd" "$@" Commented Aug 21, 2012 at 17:34
  • I don't understand the underscore notation here. The reason I am not simply using "$cmd" "$@" is that this script is being called from an OSX program which needs access to the user's environment. So in some cases I will have to call /bin/tcsh, /bin/ksh, etc. Commented Aug 21, 2012 at 18:04
  • @JCOidl I just used _ instead of some_command to shorten it. $0 isn't used anyway. However, the user's environment should be loaded when the user logs in, and inherited by all processes thereafter, so I don't see your point. Commented Aug 21, 2012 at 18:22
  • Yeah... it's confusing. OSX keeps the environmental variables available to GUI apps separate from those available to UNIX-type programs launched from the terminal. So logging in to the GUI doesn't automatically load the environment that is set in .profile or .cshrc or whatever corresponds to the user's default shell. At any rate, even substituting the program name (or $cmd) for the underscore results in a command not found error. PS - Thanks for the back and forth here. It's been incredibly useful. Commented Aug 21, 2012 at 18:38