Is it possible to run my scripts located in
~/scripts from anywhere?
Say i want to run
./scriptname regardless of my current working directory.
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
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
$PATH, but you can do the same with
~/scripts of course.
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
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:
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
If you want to see all environment variables type
env in your console.