Writing my first bash script (line 2: testscript: No such file or directory)

Posted by skyeagle on Super User See other posts from Super User or by skyeagle
Published on 2011-01-14T09:22:00Z Indexed on 2011/01/14 9:55 UTC
Read the original article Hit count: 360

Filed under:
|
|

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

This is what my 'script' looks like

cd /path/to/directory/cronscripts
. testscript

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

pwd
echo `ls -lhrt`

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

I have the following two questions

  1. Why am I getting the above error message and how do I fix it?

  2. My script seems to run fine without a shebang in the first line - infact when I try either of the following:

    • #!/usr/bin/bash
    • #!/usr/bin/bash env

I get the following error message:

/usr/bin/bash: bad interpreter: No such file or directory

What is the purpose of the shebang statement and why do I get the above error when I try to include it in my script/ how do I fix it, so I can add the shebang (is it necessary? - it seems most script examples have the shebang - but I'm not sure if it is a must, as the script runs without it).

© Super User or respective owner

Related posts about bash

Related posts about shell