Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question
3  
Note that this is almost always a bad idea, especially for the root user. –  David Schwartz Sep 27 '11 at 23:50
    
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

1 Answer 1

up vote 24 down vote accepted

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.

share|improve this answer

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.