LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   /bin/bash^M: bad interpreter: no such file or directory (https://www.linuxquestions.org/questions/slackware-14/bin-bash%5Em-bad-interpreter-no-such-file-or-directory-461400/)

stevesk 07-06-2006 01:54 AM

/bin/bash^M: bad interpreter: no such file or directory
 
Hey people! I am trying to install Slackware in a..."different" way. First of all, I install only the base. Then, I boot into my new slackware system, go to a directory where I have packages and use a simple script in shell to install them. It is something like that:

#!/bin/bash

echo Installing packages...

installpkg package1.tgz
installpkg package2.tgz
installpkg package3.tgz

BUT...when I try to run it:

/bin/bash^M: bad interpreter: no such file or directory

So I use vi to see the file and delete the damn it ^M after #!/bin/bash and surprise: there was no ^M. It is just as I typed: #/bin/bash [ENTER] [ENTER] echo Installing packages... [ENTER] ... so what could be happening? Why when I try to run the script does the command line think that there is a "^M" after every line? Is there anything I can do? Thanks! :)

Edit: The "base" are packages series "a".

bathory 07-06-2006 02:21 AM

Use vim to edit the script. You can use:
Code:

1,$ s/{ctrl-V}{ctrl-M}//
to remove the ^M characters (mind that {ctrol-V} means that you have to press ctrl+v)

Regards

Tinkster 07-06-2006 02:56 AM

And for future reference: don't create Unix/Linux scripts on a windows-box ;}


Cheers,
Tink

stevesk 07-06-2006 08:47 AM

Ok guys, I confess, I used notepad.exe to make the scripts... :cry:

It was...a moment of weakness...it shouldn't happen again ;)

Btw, thanks a lot for the help, now everything works fine! Problem Solved!

dugan 07-06-2006 12:33 PM

In the future, you can easily convert between DOS and UNIX text file formats using fromdos and todos. They are called "dos2unix" and "unix2dos" on most other distributions.

vikas027 10-28-2007 12:15 AM

Quote:

Originally Posted by bathory (Post 2322444)
Use vim to edit the script. You can use:
Code:

1,$ s/{ctrl-V}{ctrl-M}//
to remove the ^M characters (mind that {ctrol-V} means that you have to press ctrl+v)

Regards


where to put filename is this command

1,$ s/{^V}{^M}

Disillusionist 10-28-2007 10:37 AM

Quote:

Originally Posted by vikas027 (Post 2939362)
where to put filename is this command

1,$ s/{^V}{^M}

To run this you would have to open the file first eg:
Code:

vi filename

Disillusionist 10-28-2007 10:46 AM

I don't seem to have fromdos or dos2unix on ubuntu.

If you don't want to use vi, then the following sed command works just as well.

Code:

sed s/{ctrl+v}{ctrl+m}// filename > filename.tmp && mv filename.tmp filename
Please note it is not safe to read a file into sed and write directly back to the same file, you will end up with an empty file!

Once again the {ctrl+v} means press Ctrl key and the v key together.
and {ctrl+m} means press Ctrl key and the m key together.

pwc101 10-28-2007 10:53 AM

Quote:

Originally Posted by Disillusionist (Post 2939774)
Code:

sed s/{ctrl+v}{ctrl+m}// filename > filename.tmp && mv filename.tmp filename
Please note it is not safe to read a file into sed and write directly back to the same file, you will end up with an empty file!

If you use the -i option, sed will edit the original file "in-place", that is it will write the changes to the input file, so your command can be shortened:
Code:

sed -i s/{ctrl+v}{ctrl+m}// filename
and will produce the same result.

Disillusionist 10-28-2007 10:56 AM

Quote:

Originally Posted by pwc101 (Post 2939783)
If you use the -i option, sed will edit the original file "in-place", that is it will write the changes to the input file, so your command can be shortened:
Code:

sed -i s/{ctrl+v}{ctrl+m}// filename
and will produce the same result.

Thanks, I think I should revisit some man pages ;)

vikas027 05-15-2008 12:43 PM

simply run command:

Code:

dos2unix filename

adilbhilai 09-24-2008 04:34 AM

Thanks buddy
"#dos2unix filename" solved my problem

ErV 09-24-2008 04:52 AM

Quote:

Originally Posted by Disillusionist (Post 2939774)

Code:

sed s/{ctrl+v}{ctrl+m}// filename > filename.tmp && mv filename.tmp filename

This:
Code:

sed 's/\r//'
does the same and is easier to remember, IMO.

GazL 09-24-2008 05:33 AM

Quote:

Originally Posted by Tinkster (Post 2322473)
And for future reference: don't create Unix/Linux scripts on a windows-box ;}


Cheers,
Tink

I had a similar thing happen only the other day with one of my scripts (though it wasn't a /r). I was actually writing it using vi (elvis) running in an xterm. Anyway, somehow I ended up with non-printable characters in there that were breaking one of my if/fi blocks and causing the script to throw a wobbly. If it hadn't been for the syntax highlighting, I'd have had a nightmare in finding out why it wasn't working. As it was I noticed that the 'fi' wasn't highlighted and that was the giveaway.

I know the way tty/xterm works is somewhat antiquated in how it deals with input, control/escape sequences etc. It's probably safest to use a native X11 editor that isn't going to be as susceptible to this sort of thing.


edit: ah damn. responding to a resurrected thread again. I really must check the dates more thoroughly.

brianL 09-24-2008 05:48 AM

And if you do edit them on Windows, use a better text editor, such as EditPad Lite, which automatically opens files, converts files, and allows you to write files, in whatever format.

edit: ah damn. responding to a resurrected thread again. I really must check the dates more thoroughly.
Oops! me too, GazL.

power_wong 03-06-2012 09:34 PM

Create shell script in Windows for Linux/Unix
 
The problem is due to the different end of line in Windows and Linux/Unix platform. Windows is using CRLF while Linux is using LF only.
I have 2 favourite text editor that can solve this problem.
1. Context --- It has a function "Convert Text to Unix (LF Only)" under its Tools menu

2. NotePad++ --- It has an "EOL Conversion --> Unix format" under its Edit menu

I have tested them, both are working fine.
HTH

MadMaverick9 03-06-2012 10:13 PM

:cry:

http://vimdoc.sourceforge.net/htmldoc/usr_23.html#23.1

two things you need to do in Vim (not Elvis) to convert a file to unix format:

Code:

set fileformat=unix
%s/<Ctrl-V><Ctrl-M>$//

:Pengy:

wildwizard 03-07-2012 02:36 AM

Quote:

Originally Posted by stevesk (Post 2322797)
Ok guys, I confess, I used notepad.exe to make the scripts... :cry:

You should try wordpad in Windows as it is much more powerful and can actually write UNIX text files.

EDIT
Quote:

Originally Posted by brianL (Post 3290160)
edit: ah damn. responding to a resurrected thread again. I really must check the dates more thoroughly.
Oops! me too, GazL.

FFS x2

unSpawn 03-07-2012 11:58 AM

Quote:

Originally Posted by brianL (Post 3290160)
edit: ah damn. responding to a resurrected thread again. I really must check the dates more thoroughly.
Oops! me too, GazL.

And that was from 2008. Guess I'll need to help you lot. Closed.


All times are GMT -5. The time now is 05:59 AM.