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?
|
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
See this U&L Q&A "How do I test to see if an application exists in $PATH?" for a more thorough coverage. |
|||
|
|
|
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:
If your script is in any of those directories it will run without using the absolute path.
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
|
|||
|
|


#!shebang? – goldilocks Apr 25 '13 at 14:31echo $PATH. – slm♦ Apr 25 '13 at 14:39