Humble Trader

Saturday, December 17, 2005

My script won't run, mum.

Introduction:

For some reason, your shell script craps out. Let's debug it...

Aim:

To identify and fix problems with shell script execution.

1. bad interpreter


Symptom:

when you run the script, you get the error message; 'bad interpreter: No such file or directory'

Investigation:

Run this:

$ head -1 'script name' | od -c

If your output looks something like this:

- 000000 # ! / b i n / b a s h \r \n
- ^
- |
- then your problem is right here -+


What it should look like is this:

- 000000 # ! / b i n / b a s h \n

What's probably happened is that this file has been sourced from a Windoze PC. Windoze notoriously adds a carriage return (denoted by /r in the example) & line feed (denoted by /n in the example) to the end of each line. *NIX only adds the line feed.

This is also an example of the use of the 'magic number' in a script. Where the first line reads '#!/bin/bash', this tell Linux to run the script in the bash shell. Likewise, '#!/bin/sh' tell it to use the Bourne shell.

Where Windoze adds the carriage return, Linix tries to use the /bin/bash[carriage return] shell and no such thing exists.

Fix:

Fortunately, the fix is easy:

0 Comments:

Post a Comment

<< Home