Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I tried this

./home/user/scripts/someScript

but it doesn't work

No such file or directory

any ideas?

share|improve this question
2  
Obviously there isn't such a file or directory. So you give wrong path. The dot there doesn't mean "execute". It's just part of the path. In shell you normally type either files to be executed or commands(which in fact are also files) :) –  Pithikos Nov 2 '11 at 14:52
    
get rid of that starting period and try again. Alternatively, ~/scripts/someScript will also work. also keep `` qoutes in mind, and the exec programs ($man exec) –  j0h Apr 26 at 2:37

3 Answers 3

up vote 5 down vote accepted

The leading dot in your command means "relative to the current directory". Remove it and it'll refer to "the file someScript in the directory /home/user/scripts:

/home/user/scripts/someScript

If you get "Permission denied", it's either because you do not have sufficient permissions to access the file in the directory of other users or because the file is not executable. To make it executable, run:

chmod +x /home/user/scripts/someScript
share|improve this answer

Remove the .

If you make the scrip executable with chmod 755 <nameofscript> to run it you only need to type the path to the script.

When you see ./script being used it telling the shell that the script is located on the same directory you are executing it. To use full path you type sh /home/user/scripts/someScript.

share|improve this answer
    
sh /path/to/file is different from /path/to/file. sh runs /bin/sh which is symlinked to /bin/dash. –  Lekensteyn Nov 2 '11 at 14:19
    
Just making something clear on the examples you see on the net, normally you see sh ./somescript which can also be typed as `sh /path/to/script/scriptitself'. –  Bruno Pereira Nov 2 '11 at 14:37

If your script needs to access resources in the same folder that it is being run from, and you have it specified as relative paths, then your script will break.

I always add a cd $(dirname $0) to the head of my script so the folder containing the script will be the root folder.

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.