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


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


  • 3
    Note that this is almost always a bad idea, especially for the root user. – David Schwartz Sep 27 '11 at 23:50
  • 1
    What is the whole purpose/story behind the ./ anyway? – Pete Sep 28 '11 at 3:03
  • I am just curious why it always needs to have ./ – Aivan Monceller Sep 28 '11 at 3:06
  • The last comment could be a separate question IMHO - it is an important thing to understand about running programs in general! – rozcietrzewiacz Sep 28 '11 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 Sep 28 '11 at 15: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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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