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?
Best Answer
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 linesource /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):
/bin/bash -norc
Now Control-Command-A will open a session exactly the same as a GUI app would get - everything set to the
bash
default.