I'm testing some scripts which are destined for use inside various GUI Apps, either as direct shell calls or as part of an AppleScript do shell script call. I know from experience that the shell which an App gets is nothing like what I get by default when starting Terminal, so I'd like to figure out a way to simulate the shell that an App gets so that I can debug the scripts knowing that they are behaving as I should expect them to behave in their final expected use environment.

So, how to I open an Terminal (or modify one which is already open) so that it behaves like the shell that a GUI App has access to?


First, let me solve the problem of a GUI app not providing the same environment as a terminal session to a bash script.

The differences are because of your bash profile, so you can have exactly the same in a GUI shell script by using the source command. Put the line source /Users/<username>/.bash_profile (replacing <username> with your short name) at the top of your bash script and you will have the same environment in the script when run inside a GUI app as in your shell session.

To get a shell without running your profile in iTerm2 (I couldn't get it to work in Terrminal):

  • Open to Terminal->Preferences
  • Go to the Profiles pane
  • Duplicate your default profile
  • In "General"
  • Change the name of the new profile to "No Profile"
  • Set the shortcut key to Control-Command-A
  • Click on "Command"
  • Set the command to /bin/bash -norc
  • Close the Preferences

Now Control-Command-A will open a session exactly the same as a GUI app would get - everything set to the bash default.

| improve this answer | |
  • Sourcing in the profile does not solve all the problems. GUI apps, for instance, do not read-in modifcations to PATH from /etc/paths.d/ the way Terminal does. I think there might be some other environment variable issues too, but I haven't been able to nail them down yet. Still, I'll look into iTerm2 and see how much closer that gets me to where I need to be. – rpspringuel Apr 18 '18 at 18:54
  • The minor differences you have found are due to a GUI app not running /etc/profile. The only one of significance is the PATH, apologies for forgetting it, I explicitly set mine in my profile. The others are all terminal and Terminal related. Using the iTerm2 solution fixes all that, too. – Tony Williams Apr 18 '18 at 20:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .