3

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.

MikeyB
  • 39,291
  • 10
  • 105
  • 189
Kredns
  • 496
  • 1
  • 8
  • 15

4 Answers4

19

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.

MikeyB
  • 39,291
  • 10
  • 105
  • 189
6

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.

3

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.

Matthew
  • 33
  • 3
  • 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 09:03
1

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

John Gardeniers
  • 27,458
  • 12
  • 55
  • 109