Linux shell scripting: bad interpreter: No such file or directory



 

This error pops up for a couple of reasons. At the top of the script there will probably be a line that looks like this:


#!/bin/sh 


This is telling Linux that this script should be interpreted using the /bin/sh program. So your first step is to verify that program exists. I tend to use:

which sh
 
This will typically come back with a response like this:

/bin/sh

 
This is telling us that the path to the sh program is in fact /bin/sh, matching the path specified at the top of the script. Ok, so what gives? Well, it's possible that this script was made on an operating system that has line ending characters different than linux. This could have been on on a Mac or PC, or the file could have been converted when it was packaged. In this case, you get the relatively misleading bad interpreter: No such file or directory message, which is really trying to look for sh, although you don't get any indication of the fact.

So, how to fix? Read on.
There are various ways to fix the problem, but I find one of the simplest being the use of vi which is standard on most unix systems, and in linux comes in the form of the vim package. Load the script up in vim, by typing

vi filename (where 'filename' is the name of your file
vi is a text based dinosaur in the day of wysiwyg editors, so if you don't know your way around, make sure you follow these steps carefully.

Once the file is loaded type:
:set fileformat=unix 
And hit Enter/Return.

You won't notice anything, but the file has already been fixed. Now all you need to do is save and exit.
:wq!
Again Return, and you should be back in your shell. Run the shell script, and if all goes well, it should now execute properly, and without the dreaded bad interpreter: No such file or directory message.


Debora, 21-11-11 10:57:
If you want to buy a car, you would have to get the <a href="http://goodfinance-blog.com/topics/mortgage-loans">mortgage loans</a>. Moreover, my mother all the time uses a small business loan, which seems to be the most rapid.

Add comment

* - required field

*

CAPTCHA image for SPAM prevention
If you can't read the word, click here.
*
*
 

Netdip.com is an excellent web site that's powered by TYPO3 and other great open source software. Netdip.com is also a fat free alternative to ice cream.