Linux shell scripting: bad interpreter: No such file or directory Mon, Sep 15. 2008
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:
This will typically come back with a response like this:
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
So, how to fix? Read on.
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:
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.
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.
- PHP Mysql support: mysql or mysqlnd?
- Showing your git branch in your shell prompt
- Centos, Amazon Linux, NFS and the dreaded "nobody" problem
- Run a Centos Lamp development server on XP, Vista or Win 7 using VirtualBox
- Xen 3.0 Fedora Core, RHEL, Centos 4.x How-to
- Install Xwindows and Gnome on Centos with Yum
- Lampsig and SCALE
- Redhat RPM reference notes
Elsa Machado on : Elsa Machado
forums.hardwarezone.com.sg on : PingBack
Confluence: City Girl on : City Girl Development Environment
#1 - chrashoverraid 2008-10-14 14:35 -
Thank you, i am a linux noob and had this problem!
now its working :)
I encountered this problem too. The funny thing is that the script was written in the linux environment. Still had to fix it. No clue as to how it got contaminated with that in the first place :o
#2.1 - OrthodoxCaveman 2012-01-17 02:34 -
Happens the same with me, can't find any info on it too...
#3 - Andrei 2009-02-11 10:31 -
Great fix, thanks!
#4 - Double O 2009-11-20 08:20 -
I think even,
should do the trick..
#6 - Richa Sabharwal 2010-03-01 11:06 -
Thanks a ton!! I had the same problem. The script was sent to me as an attachment in the email. The fix worked like a charm for me on Snow Leopard OSX.
#7 - Lee 2010-04-01 16:28 -
You are correct sir!
#7.1 - Anil 2010-06-23 19:56 -
Gr8, helped me.
#9 - kirubakaran 2010-08-14 09:50 -
Thanks a lottttttttttt, it works wellllll
#10 - VC 2010-08-26 06:19 -
Thank you!!!! This helped me a lot!!
#11 - runbux 2010-09-01 03:01 -
Didn't work. The Linux file structure is so arbitrary and incomprehensible -- On Purpose! Why can't it just work?
its not wokring now, i have a ksh and when i do
nothign dint worked for me.
- Anil K
#13 - Han Solo 2010-12-09 17:35 -
This works ! Awesome, TY
#14 - Ravi 2010-12-29 13:26 -
Wow......... that was a greate information.. It helped me alot.. Thank you very much....Have a greate day
Thank you so much!!! I had spent hours trying to get my script to work and eventually stumbled on your blog. How could I be so stupid? lol.
Thanks for taking the time to post this - I'm sure it has helped countless people a HUGE headache :)
#17 - Denver Green 2011-06-08 20:44 -
Solved my problem. Thank you for posting this information!!!
#18 - Glendon 2011-06-22 21:15 -
Thank you. Worked perfectly for me.
#19 - Blake 2011-08-03 21:44 -
Thank you, this saved me some headache.
#20 - ahmed 2011-08-28 02:45 -
thanks it work great
#21 - Linux worker 2011-09-08 12:49 -
I have a problem when I did the following step:
auxin@auxin-DQ45CB:~/Downloads/Propagation1d$ /Chaste.sh ChasteParameters.xml
bash: path_to_chaste: No such file or directory
I don't know how to fix the problem,I tried several method to set path but it didn't work.
I would be happy if you help me to resolve this problem.
#23 - Tanmay 2011-10-03 08:18 -
#24 - Shindu 2011-10-17 09:26 -
Thx, great info.
#25 - K0h4n 2011-12-22 00:56 -
It works like a charm. Thank you for the solution. ^^
#26 - Maurice 2012-01-20 16:26 -
I works for me as well; thank you very much.
A million thank-you's. I was editing a file on someone else's system. Being the Linux-challenged person, I had transferred it over to Windows, edited and transferred back. I was going round and around and finally Googled the error message, which brought me here. 3 minutes later I'm back in business. Ginormous Gracias!
#28 - 3l4d2 2012-03-26 07:31 -
thanks! works like a charm!
#29 - Robert 2012-04-25 23:12 -
I had big problems trying to run python script written under Windows on Debian. I've searched many sites and finally I've found your solution. It is working like a charm. Thank you very much.
#31 - Mike 2012-07-01 00:03 -
Great, works perfectly thank-you!
#32 - David 2012-07-11 06:51 -
Awesome! Thanks for this article. Saved me some headache.
#33 - fuzzycheck 2012-08-09 13:19 -
the procedure didn't work for me, but I found the reason: the file must not have a BOM, in addition to being in Unix format.
I create my scripts in Notepad++, and it gives the option of saving files in UTF8 format with a BOM, or without a BOM. The BOM adds a few characters at the beginning of the file.
You can check with hexdump:
a file with BOM:
hexdump -C compile_gtk.sh
00000000 ef bb bf 23 21 2f 62 69 6e 2f 73 68 0a 0a 46 49 |...#!/bin/sh..FI|
same file without BOM:
> hexdump -C compile_gtk.sh
00000000 23 21 2f 62 69 6e 2f 73 68 0a 0a 46 49 4c 45 3d |#!/bin/sh..FILE=|
The difference is the first 3 bytes "ef bb bf".
In VI, to check if the file has a BOM, type ":set bomb?". A message "bomb" or "nobomb" should appear.
To remove the BOM, type ":set nobomb", then save the file. Check again with hexdump that the BOM was removed.
#34 - zz 2012-11-12 04:03 -
Thanks for posting this fix!
Haven't used *nix in a while but it's now slowly becomming a bigger part of my life...
(lots of memory work)
Thank you for posting this. I spent two days of frustration and desperation trying to get a simple cron working. You saved me from losing my mind! :-)