File Extension

.sh is typical (but not mandatory)

File Contents

The file should start with:


#!/bin/bash

If there is a problem with the interpreter being found type error message you can see where your systems bash interpreter is by typing "which bash" on the command line.

Blank lines are fine.

Use the # character for comments

Rules For Bash Files

Don't create the file in Widows notepad as you'll have incorrect line endings (carriage return, linefeed instead of the Unix linefeed only).  This will cause the line "#!/bin/bash" to give this error:


/bin/bash^M: bad interpreter: No such file or directory

^M is the carriage return character.   You can correct this by opening the file in Leafpad, selecting Save As and changing the Character Coding from CR+LF to LF

Things you can do

Press return to move on

#!/bin/bash

echo "Press return to start"
read dummy
echo "Ok here we go"
Pause

#!/bin/bash

echo "Starting"
sleep 1
echo "Ok here we go"

 

Problems

^M: bad interpreter: No such file or directory

See CR+LF problem in rules

Not found "/r" errors or general errors with lines that should be fine

See CR+LF problem in rules

Script won't run

Set the file permissions so its executable

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *