1

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".

1 Answer 1

6

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.

1
  • 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, 2012 at 8:02

You must log in to answer this question.

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