0

I have a set of folders with scripts in them. These are used to setup various environments. Each folder also has a plain text file that has some settings that are read by the script (so that the settings only need to be updated in one place and can be read by the bash or powershell scripts).

I have another folder that contains scripts that take parameter to determine which folder to execute the script from. This folder in in the PATH, so that the scripts can be called as you would an executable.

Now, I am have gotten this to work on windows, where I am a bit more familiar, however making this work on Mac has not been kind to me. I do not want (the users) to have to source the file, I want the script to do that automagically (as is working on Windows).

script root
-scripts
--env_a
--- settings
--- bash script for env a
--- posh script for env a
--env_b
--- settings
--- bash script for env b
--- posh script for env b
-path
--set_env.sh
--set_env.bat

So on Windows, I can > set_env env_a, and the environment variables are available to the current and child processes. How can I do the same on Mac?

Pezius
  • 117
  • 3
  • 12
  • You're asking for the impossible. On Windows, a batch file is run by the interpreter's interactive shell, which is why it's able to change that shell's state. On Linux, a script is run by a new interpreter. **You can't change that from the script,** because by the time the script is running, the new, separate process it runs in was already created. – Charles Duffy Mar 08 '18 at 00:45
  • From a security and predictability perspective, this is a Good Thing -- the Linux model means that scripts can be on the other side of a privilege boundary from the user that invokes them, and that a user can be assured that there won't be any unintended effects on process state. If you *want* those effects... well, that's why programs like `ssh-agent` tell users to use `eval` to invoke their output. – Charles Duffy Mar 08 '18 at 00:47
  • Anyhow, this is asked and answered, many many times. Not liking the answer isn't an excuse for asking a duplicate question. – Charles Duffy Mar 08 '18 at 00:48
  • Thanks @CharlesDuffy. I do apologize for asking what you feel is a duplicate question; I do not however find your last response to be helpful in any way other than to alienate someone trying to grow additional knowledge. I have search for over 12 hours on this topic, and when I finally decided to ask the question, which seems to be not answered by any of the posts I've found, I've been greeted with and rudeness. This has nothing to do with not 'liking' an answer; but with not finding any answer to me question at all. Thanks for clarifying the limitations of *nix OSes and the SO community. – Pezius Mar 08 '18 at 01:08

0 Answers0