Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two shell script files with exactly the same permissions etc. I can run one of them by just giving its name in the command line but for the other one I should use sh or ./ to run it. What is the reason?

share|improve this question
Are the 2 scripts in the same directory or different locations? – slm Apr 25 '13 at 14:31
No #! shebang? – goldilocks Apr 25 '13 at 14:31
No, both have it! – coffeMug Apr 25 '13 at 14:33
@slm: different directories. – coffeMug Apr 25 '13 at 14:34
What are the directories? Check to see if either is on the $PATH env. variable. echo $PATH. – slm Apr 25 '13 at 14:39
up vote 3 down vote accepted

Odds are that the 2 scripts are in different directories. One of the directories is on the PATH while the other is not.

You can use the type command to test if a file is present on your current shell's $PATH.

$ type start_dropbox.bash
start_dropbox.bash is /home/saml/bin/start_dropbox.bash

See this U&L Q&A "How do I test to see if an application exists in $PATH?" for a more thorough coverage.

share|improve this answer

If you're just giving the name of the script and it works then you have it in your /usr/bin/ /usr/sbin or whatever. It all depends on what your path is set to.

Do this:

1. echo $PATH

If your script is in any of those directories it will run without using the absolute path.

2. whereis "scripts name"

Whereis or "which" will tell you where it's located. You may even have given one file execution rights and not the other. For the one that doesn't run with just the name do a chmod u+x

  1. You may need to add #!/usr/bin/env python if its a python script or #!/usr/bin/env bash if its bash and so on.
share|improve this answer

Your Answer


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.