Is it possible to run my scripts located in ~/scripts
from anywhere?
Say i want to run ./scriptname
regardless of my current working directory.
Is it possible to run my scripts located in ~/scripts
from anywhere?
Say i want to run ./scriptname
regardless of my current working directory.
You can add ~/scripts
to your $PATH
environment variable. Then you can run scriptname
from anywhere (but not ./scriptname
, because the ./
denotes the current directory).
This answer shows how to add ~/bin
to $PATH
, but you can do the same with ~/scripts
of course.
Add
export PATH=$PATH:~/scripts
to your the end of your ~/.bashrc
file. This will allow you to execute your scripts in ~/scripts/
by simply typing scriptname in the bash.
You need to logout in order for it to work in your session (you can test the scripts by opening a new terminal).
I usually add
export PATH=$PATH:~/bin
to my path and then create symlinks to the scripts an programs I want to have available in my session.
cd ~/bin
ln -s ~/Tools/eclipse3.7/eclipse
# which will create a symlink in ~/bin/ with the name eclipse
# pointing to ~/Tools/eclipse3.7/eclipse which allows me to execute
# the eclipse in ~/Tools/eclipse3.7/
Note that the path files have a precedence. If I already have installed eclipse through ubuntu, it will first search eclipse in all other places than in ~/bin/
. If you want to change this behavior just export the directory the other way around:
export PATH=~/bin:$PATH
Make sure the scripts in your scripts directory are executable otherwise the export won't have an effect.
You can look at the available paths by typing
echo $PATH
If you want to see all environment variables type env
in your console.
Two ways:
./
, like ~/scripts/scriptname
$PATH
environment variable and call your shell scripts without the leading ./
, like scriptname
PATH
. This way I can use my „own version” of commands. And as a side note, you don't need the trailing slash after the directory name. – lgarzo Jun 19 '12 at 20:26