Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I used to know a way to run my shell scripts just by typing there name as long as there were in my home folder or desktop. I hate having to type ./myscript.sh. I would like to be able to type just myscript.sh. How can I fix my terminal to do this?

I'm using GNOME Terminal and Ubuntu 9.04.

share|improve this question

4 Answers 4

up vote 19 down vote accepted

It's a bad idea to put the current directory into your path. Move your scripts that you want to frequently run into ~/bin and then add ~/bin to your path.

To do this, add:

export PATH=$PATH:~/bin

to ~/.bash_profile.

share|improve this answer
    
Thank you! Why is this so hard to find on google? –  Lucas McCoy Jul 11 '09 at 3:05
3  
+1 for "It's a bad idea.."! –  Arie K Jul 11 '09 at 3:10
3  
@Lucas: It's no longer hard to find on Google :) –  MikeyB Jul 11 '09 at 3:18
    
@MikeyB: SF saves the day again! –  Lucas McCoy Jul 13 '09 at 21:39

You can add . to the path, but as MikeyB says, it is a bad idea.

The reason it is a dangerous thing to do is that if a malicious bit of software with the same name as an executable you are running exists in the current directory, that will be run instead.

share|improve this answer

I put my shell scripts in /usr/local/bin, seems the best place for them? it's usually empty. Make them executable and forget the .sh extension, and you can just call them plainly.

That's on Ubuntu server.

share|improve this answer
1  
/usr/local/bin is the right place for scripts that are meant for all users. ~/bin is for scripts for that user. Of course it doesn't matter if you're the only user... –  sleske Jul 23 '09 at 9:03

To answer the question that was asked, add your home directory and the desktop to the path.

share|improve this answer
    
+1, and the lesson is: be careful what you ask for :-) –  DutchUncle Feb 24 '11 at 17:38

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.