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.
#1 - chrashoverraid 2008-10-14 07:35 -
Thank you, i am a linux noob and had this problem!
now its working :)
#2 - .xghost said:
2009-01-29 09:58 -
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-16 18:34 -
Happens the same with me, can't find any info on it too...
#3 - Andrei 2009-02-11 02:31 -
Great fix, thanks!
#4 - Double O 2009-11-20 00:20 -
I think even,
$dos2unix name-of-file
should do the trick..
#6 - Richa Sabharwal 2010-03-01 03: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 09:28 -
You are correct sir!
#7.1 - Anil 2010-06-23 12:56 -
Gr8, helped me.
friend.kak@gmail.com
#8 - Vladimir Tsukur said:
2010-07-24 07:02 -
Thank you. Your post helped me to resolve the issue
#9 - kirubakaran 2010-08-14 02:50 -
Thanks a lottttttttttt, it works wellllll
#10 - VC 2010-08-25 23:19 -
Thank you!!!! This helped me a lot!!
#11 - runbux 2010-08-31 20:01 -
Didn't work. The Linux file structure is so arbitrary and incomprehensible -- On Purpose! Why can't it just work?
#12 - Anil K said:
2010-12-08 13:34 -
its not wokring now, i have a ksh and when i do
:set fileformat=unix
and dos2unix
nothign dint worked for me.
?
- Anil K
#13 - Han Solo 2010-12-09 09:35 -
This works ! Awesome, TY
#14 - Ravi 2010-12-29 05:26 -
Wow......... that was a greate information.. It helped me alot.. Thank you very much....Have a greate day
#15 - Craig Fairhurst said:
2011-02-14 15:21 -
Worked, thanks
#16 - Kevin McCaughey said:
2011-06-08 05:24 -
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 13:44 -
Solved my problem. Thank you for posting this information!!!
#18 - Glendon 2011-06-22 14:15 -
Thank you. Worked perfectly for me.
#19 - Blake 2011-08-03 14:44 -
Thank you, this saved me some headache.
#20 - ahmed 2011-08-27 19:45 -
thanks it work great
#21 - Linux worker 2011-09-08 05:49 -
Hi,
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
auxin@auxin-DQ45CB:~/Downloads/Propagation1d$
******************
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 01:18 -
Great!!!
#24 - Shindu 2011-10-17 02:26 -
Thx, great info.
#25 - K0h4n 2011-12-21 16:56 -
It works like a charm. Thank you for the solution. ^^
#26 - Maurice 2012-01-20 08:26 -
I works for me as well; thank you very much.
#27 - Anne of No-Work Spanish said:
2012-03-03 06:38 -
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 00:31 -
thanks! works like a charm!
#29 - Robert 2012-04-25 16: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-06-30 17:03 -
Great, works perfectly thank-you!
#32 - David 2012-07-10 23:51 -
Awesome! Thanks for this article. Saved me some headache.
#33 - fuzzycheck 2012-08-09 06:19 -
Hi,
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-11 20: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)
#35 - Jim said:
2012-12-06 15:10 -
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! :-)



Tracked: May 12, 03:09
Great article post.Thanks Again. Much obliged.
Tracked: Dec 15, 18:15
Tracked: Jan 02, 06:20
City Girl Development Environment Liddles uses Git (
Tracked: Jul 23, 17:32