Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a script in /home/username/scripts and I would like to execute it by just typing its name.

I know I could do 'export PATH=$PATH:/home/username/scripts' but I would like to have the same effect without having to export the path each time. For instance, if another user was to have a copy of the script they could just type "scriptname.sh" instead of "./scriptname.sh".

share|improve this question
up vote 6 down vote accepted

Either put it in one of the existing directories in $PATH, or define an alias that points to the appropriate path.

cp scriptname.sh /usr/local/bin

...

alias scriptname.sh=/home/username/scripts/scriptname.sh

The last could be done in every users ~/.bashrc (for the users who need it). Alternatively you could add the PATH to the user's ~/.bash_profile. Possibly changing the default ~/.bash_profile in /etc/skel so new users get this automatically.

If the script should be available for all users, coping it to a system wide PATH, as mentioned above, is the best option.

share|improve this answer
    
I strongly recommend you to leave your script in your home (/home/username/somewhere) with proper permissions and put a symlink to /usr/local/bin as suggested. This way you will hopefully not forget to backup the script as you will usually backup your home folder. – math Apr 10 '12 at 8:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .