am28
am28

Reputation: 381

SETLOCAL equivalent for Mac

I have a windows batch script where I use SETLOCAL to set path variables for that session only. Is there a Mac equivalent for that command scripts?

Upvotes: 0

Views: 756

Answers (2)

dolmen
dolmen

Reputation: 8696

In Unix shells (such as with bash or sh on Mac OS X), all variables set in a shell script do not survive the end of the shell script. This means that SETLOCAL is already the standard behaviour. In fact the non-SETLOCAL behaviour is not possible from the script itself (but the launcher of the shell can still order the shell to run the script in the current shell with the 'source' command to have that behaviour).

For the variable to be visible to programs launched from that session, you have to export the variable:

export BAR=1

Upvotes: 0

AllenMoh
AllenMoh

Reputation: 476

The Unix/Mac equivalent would be the export command:

export FOO=1

http://www.cyberciti.biz/faq/linux-unix-shell-export-command/

Upvotes: 1

Related Questions