do shell script "env" -- different result than in terminal

I need to run a series of shell scripts, and need to confirm that certain environmental variables are set up, but the list of variables is incomplete if I check from applescript rather than terminal. How can I get the full list?

running this:

on run
	set EnvVars to do shell script "env"
	return EnvVars
end run

Thanks,

Tim

Hello.

Look for how to set environment variables with launchd the explanation for not seeing them from AppleScript, is that both the terminal, and Applescript are launched under the init process, so one can’t see the variables set by the other, with launchd, you create the variables in process 0 ( init process), and all other processes launched after that will see your variables.

Edit
if it is just one or two variables, then nothing hinders you in declaring them before the main part of your shell script runs, like so:

do shell script "export var1=\"a value\" ; export varb=\"another value\""

Still another solution would be to have those variable set in a shell script that you execute with the . operator( you source the shell script) or maybe the source keyword.

If you modify your .login, or .bashrc to source the same file, then you gain consistency.

Hopes this helps.

The difference in variables is because do shell script uses the shell of the current application it’s running in. If you have an script open in script editor and run your code, the code is run in the shell of script editor. The terminal does have it’s own shell like a do shell script command but it uses an pseudo terminal (TTY) on top of it which needs it’s own variables. Basically the difference in environments variables and variables (can be obtained by command set) are mostly in terminal settings, because do shell script doesn’t have one.

Bash is also launched differently, do shell script launches bash in an non-interactive mode while Terminal obviously does lauch bash in an interactive mode. So variables like PS1, PS2 and PS3 are not needed to be set for a do shell script while it needs to be set when opening a Terminal.

Simply put, if you need those variables in a do shell script then you’ll probably need a terminal because those missing variables are only Terminal related and not shell related.