[Newbie Q] Shell Script Problem

beyonddc

Senior member
May 17, 2001
910
0
76
Hi, I am trying to run a shell script that bundled with the program that I downloaded.
I am currently using Fedora OS.

The shell scripts begin with
#!/bin/sh

When I execute in my Terminal, I received the following error.
bash: /development/JacORB/bin/jaco: /bin/sh^M: bad interpreter: No such file or directory

I am not sure how to fix it with my limited knowledge on Linux.
I verified that "/bin/sh" is in my path by doing a "ls /bin/sh" and executing the "sh".

It will be great if someone can help me with this.

Thanks!!! :
 

cleverhandle

Diamond Member
Dec 17, 2001
3,566
3
81
Originally posted by: beyonddc
bash: /development/JacORB/bin/jaco: /bin/sh^M: bad interpreter: No such file or directory
Because the file is using Windows-style end-of-lines (Carriage Return + Line Feed) rather than Unix ones (just Line Feed). The "^M" is the Carriage Return character, and it's going to hang up bash. Sometimes this is caused by ftp'ing a file in the wrong mode or from transferring it from a windows filesystem, sometimes it's just slop.

You can fix it with...

sed -i.orig 's/^M//g' name-of-script

There's also a utility named dos2unix (and a unix2dos) to handle this sort of thing in a little more friendly manner.

 

drag

Elite Member
Jul 4, 2002
8,708
0
0
It's probably because it's using DOS/Windows-style end line deliminators.

Unix systems and Windows systems use different special characters to determine line breaks. (unix was first btw, don't know why MS choose to use something different)

Used to be when you edited a text file in Unix the lines would always show up and make it obvious that your working in a file from a windows system. Nowadays most text editing programs detect this automaticly and adjusts for it, but you can run into problems with shell scripts and such.

On linux systems there is a dos2unix or unix2dos program to change a dos text file to a unix text file and visa versa.

Otherwise if you don't have those there are a veriaty ways to convert formats.
http://www.vasudevaservice.com/document...-to/converting_dos_and_unix_text_files

 

drag

Elite Member
Jul 4, 2002
8,708
0
0
Originally posted by: cleverhandle
Originally posted by: beyonddc
bash: /development/JacORB/bin/jaco: /bin/sh^M: bad interpreter: No such file or directory
Because the file is using Windows-style end-of-lines (Carriage Return + Line Feed) rather than Unix ones (just Line Feed). The "^M" is the Carriage Return character, and it's going to hang up bash. Sometimes this is caused by ftp'ing a file in the wrong mode or from transferring it from a windows filesystem, sometimes it's just slop.

You can fix it with...

sed -i.orig 's/^M//g' name-of-script

There's also a utility named dos2unix (and a unix2dos) to handle this sort of thing in a little more friendly manner.

Ya beat me.