I am attempting to write my first shell script (I'm running Ubuntu 10.x)

This is what my 'script' looks like

cd /some/path/to/scripts
# pwd (if uncommented, this shows we HAVE really changed directory to /some/path/to/scripts
# echo `ls`  (if uncommented, shows that testscript is in our working directory)
# the next line is where bash LIES:  'testscript: No such file or directory' 
. testscript # (./testscript doesn't work either)

I put the following debug statements (after the cd), in the script above to make sure everything was ok:

echo `ls -lhrt`

and it displayed all the files in the directory. So I dont understand the error message I am getting.


I have changed my question - to focus on the MAIN issue as to why I am getting the 'No such file or directory' error message.

Here are the facts:

  • testscript is executable and resides in /some/path/to/scripts
  • when I manually type the commands in the script above, testscript runs successfully

My question then is this:

How is it that these same (trivial) commands work on the command line, and yet fail to work when executed from a batch script?.

Equally (if not more important), is the question - how do I fix this?

Put simply I want to write a script that does this:

  1. Change directory into a specified (hard coded) one
  2. Run a script in the current working directory
  • Is bash actually in /usr/bin, or /bin? – ta.speot.is Jan 14 '11 at 9:29
  • Mine is in /bin (Debian) ;) – fakemustache Jan 14 '11 at 9:30
  • It appears that you've found your own answer to your revised question (in a comment at the linked question on SO). You should link your accounts on the two sites. Also, it's preferred that you not cross-post. Heavy revision of a question makes earlier answers not make sense. – Paused until further notice. Jan 14 '11 at 21:40

The shebang is pointing to the wrong location for the interpreter, it should be the absolute path, which (since you want to use bash for the script) is most likely:


The purpose of the shebang is to explicitly state the interpreter that the script should be run with. If you do not specify an interpreter, it will be run on whatever interpreter you are running at the time it is run.

edit: I only just noticed you have another error listed in your title. This is probably because you are using . testscript, which most likely is supposed to be ./testscript (if you are trying to execute it). Make sure you have done chmod +x to make the script executable, or it will fail.

  • testscript already has the executable flag set (it runs if I cd to its folder and type ./testscript). This is exactly the same commands in my wrapper script - so I don't understand why it reports 'no such file or directory). using EITHER . testscript or ./testscript results in the same error mesage. The only thing I can thing of is that the cwd is immediately reset after thecd command - but then again, that can't be because if I enter pwd aafter the cd command, it shows I have successfully changed the working directory. SO whats going on? – skyeagle Jan 14 '11 at 12:13
  • Try using an absolute path. – Matthieu Cartier Jan 16 '11 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.