10

On some tutorials over the internet they can run a script on the current directory without doing:

./script

How do you omit this? I am using CentOS 5.6 x64. I want to run it this way

script

5
  • 3
    Note that this is almost always a bad idea, especially for the root user. Commented Sep 27, 2011 at 23:50
  • 1
    What is the whole purpose/story behind the ./ anyway?
    – Pete
    Commented Sep 28, 2011 at 3:03
  • I am just curious why it always needs to have ./ Commented Sep 28, 2011 at 3:06
  • The last comment could be a separate question IMHO - it is an important thing to understand about running programs in general! Commented Sep 28, 2011 at 6:31
  • 4
    @Pete (and Aivan): In Linux/UNIX, the shell only runs programs if it knows the path to them (whether by using a path you specify, or by searching the PATH variable). It doesn't assume that you want to search the current directory like Windows does. It searches exactly what you ask it to search via the PATH variable. '.' is a reference to the current directory. So when you type in './script.sh', you are telling it the path.
    – Kasius
    Commented Sep 28, 2011 at 15:26

1 Answer 1

26

Any of:

  1. Add the current working directory to your PATH: PATH=${PATH}:. (this is considered a security risk)
  2. Explictely add the path containing your script to the PATH-variable (this is no security risk if write-access to that directory is limited)
  3. Put your script into the proper place where PATH already points to (~/bin, /usr/local/bin, ...)

The last option is possibly the best.

0

You must log in to answer this question.

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