Indeed, elements in $PATH are separated with colons (
, not semicolons (
Semicolons terminate a command, so executing
will actually run the 3 following commands:
export PATH=/some/path; #this effectively changes $PATH
If the latter 2 are directories (not executable programs), then you'll get shell errors about unknown commands or alike.
Secondly, I'd like to explain a bit of what is going on internally. Each program, when it is started, inherits the environement variables (including $PATH) of the shell/program that it was launched from (called the parent). In your case, you want to run a shell script, so your shell script will inherid $PATH from the shell you call it from - in your case, your command line (terminal). The program can then proceed to use, change or disregard the environment, in any way it likes, but the bottom line is that the environment is "stored" in a memory structure for each program that runs (called a "process"). When a program "inherits" the environment from it's parent shell/program, the environment information from the parent's memory structure is simply copied to that of the program itself. So, when the program stops, it's memory structures get cleaned up, so any changes it has done to it's own environment are thrown away.
Hence, if your script changes $PATH, it does so in it's own environment, which can only impact your script itself and any programs launched from that script. When your script finishes or stops, it's environment is thrown away, so the parent will never get to see the changes to the environment that were done by the script.
To make a long story short:
your command line (terminal) shell => has it's own copy of $PATH
you call your script => $PATH is copied to the script's environment (in memory)
your script modifies it's own copy of $PATH and can execute any programs/commands that will all see this modified $PATH
when your script is finished, it's memory structures are thrown away, so the modified $PATH is lost
your command line shell is still left with it's own, unaltered copy of $PATH
So, if you want to write a script that you can call to change $PATH, you can't. The only way you can perform this, is by "sourcing" the script instead of calling it.
Think of "sourcing" as including the script's contents in yours (like a #include statement in C, if you know that).
So, let's assume that you have this script:
Instead of simply calling
which would have no effect on your $PATH, since only addPath.sh's $PATH would get changed,
you'll need to "source" addPath.sh, either via
This works as if it copied the "export" command from addPath.sh into your script, so it will actually execute the "export" as if it was written in your script. The only advantage here is that you can "source" the addPath.sh script in as many of your scripts as you want (it's re-usable).
If you don't want this hassle, but instead want to always add a certain path to your $PATH, you could put it in /home/you/.bashrc, /home/you/.kshrc, /home/you/.cshrc (depending on the shell you're using), or in /home/you/.profile (applies to all shells).
Or, if you want to apply it for all users (not just you), you could even put it in
/etc/profile (all shells)
/etc/bashrc (only bash)
/etc/kshrc (only ksh)
Note that in some cases, underscores can be used in the names of these files.
Note also that you probably need to have root user access in order for you to change the files in /etc.