When you run a shell script, it executes in a sub-shell. What you need is to execute it in the context of the current shell, by sourcing it with:
source myshell.sh
or:
. myshell.sh
The latter is my preferred approach since I'm inherently lazy.
If you're talking about system-wide scope inasmuch as you want to affect everybody, you'll need to put your commands in a place where they're sourced at login time (or shell creation time), /etc/profile
for example. Where you put your commands depends on the shell being used.
You can find out what scripts get executed by examining the man
page for your shell:
man bash
The bash
shell, when invoked as a login shell (including as a non-login shell but with the --login
parameter), will use /etc/profile
and the first of ~/.bash_profile
, ~/.bash_login
or ~/.profile
.
Non-login bash
shells will use. unless invoked with --norc
or --rcfile <filename>
, the files /etc/bash.bashrc
and ~/.bashrc
.
I'm pretty certain it's even more convoluted than that depending on how the shell is run, but that's as far as my memory stretches. The man
page should detail it all.