Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Have a look at this terminal output...

bjorn@jungleland:~$ cd bin
bjorn@jungleland:~/bin$ ./first.sh 
Hello World
bjorn@jungleland:~/bin$ cd ..
bjorn@jungleland:~$ pwd
/home/bjorn
bjorn@jungleland:~$ echo $PATH
/home/bjorn/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/bjorn/bin
bjorn@jungleland:~$ ./first.sh
bash: ./first.sh: No such file or directory
bjorn@jungleland:~$ 

How come first.sh isn't found when I'm in my home directory? I have tried logging out and in again!

share|improve this question

1 Answer 1

up vote 6 down vote accepted

Because you are specifically running ./first.sh, i.e. a script called "first.sh" that is in the current directory (./). Whether it is in the $PATH or not is irrelevant. If you give a full path, as you are doing, the system will look for the executable at the path given. Compare the commands below:

/bin/ls      <-- works
ls           <-- works
../../bin/ls <-- works if you are in $HOME
./ls         <-- fails unless you are in /bin

What you want to run is first.sh instead of ./first.sh.

share|improve this answer
    
Oh so that's what the ./ is for! That explains alot. I always figured it was some kind of way to tell bash I was trying to run a script, as opposed to invoking a native command. Thank you! –  Björn Andersson Jan 10 '13 at 6:41

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.