Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.