4

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?

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

6 Comments

The tilde- ~ does not expand to the users home folder when it is enclosed in quotes.
@fd0: better now! Thanks for the catch!
Awesome, thanks. This should permanently include all shell scripts in that directory?
@JesseJamesRichard : Yes it will!
Is there a way to create a script which updates the path for the current terminal session yet not in a permanent manner as writing it into .bashrc? Or maybe open a new terminal from a script with the updated path?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.