Reputation: 493
I've written a shell script on my Mac that runs fine from the folder. Trying to make it globally executable I've used the following script:
export PATH="$PATH:~/scripts"
Subsequently, I can run the command blaster
from any folder. However, if I close my terminal window, it seems that the PATH gets lost and I have to run the original command again. Any idea why that export PATH
needs to be re-established?
Upvotes: 4
Views: 8511
Reputation: 85580
No they won't
Because your current export
is retained in the current shell you were running the scripts from. As soon as the shell is terminated, the exported variables loose their scope. Add a line
echo 'export PATH=$PATH:~/scripts' >> ~/.bashrc
To make the changes permanent, add the line in either of .bashrc
/.bash_profile
or .profile
depending upon your login shell. These files are read and sourced ( executed in the current shell) before your prompt appears, and from subsequent point you can call your script directly
Upvotes: 6