Link to home
Start Free TrialLog in
Avatar of Los Angeles1
Los Angeles1

asked on

Linux bash script execution problem

I am running RHEL 6.2,

I run the a bash script which works well in RHEL 5.6

The name of the script is

net

Open in new window


The top of the script contains:

#!/bin/bash
SPEED=10000000000
.....

Open in new window


when I run the file I get the following:

[root@Blacktip02 WMB]# ./net
-bash: ./net: /bin/bash^M: bad interpreter: No such file or directory
[root@Blacktip02 WMB]#

Open in new window



I check to see if bash is there, and it is


[root@Blacktip02 WMB]# cd /bin
[root@Blacktip02 bin]# bash
[root@Blacktip02 bin]#

Open in new window



What should I do ?
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Your script contains carriage-return characters at the line ends.

Did you transfer it from Windows in text mode (instead of binary mode)?
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tintin
Tintin

or just do
dos2unix net

Open in new window

BTW, the commands you used to find bash work differently on Windows Command Shell and Linux:

   # cd /bin
   # bash

The second will run bash from where ever it is found on the PATH, which may not be in /bin.  If /bin/bash did not exist (it does on RHEL), you would still get the same result.

If you want to find where bash is located, run "which bash".  To confirm that it is in /bin, run "ls /bin/bash".

BTW (2):  Avoid developing or running scripts as root.  It is very easy to mistype a command and turn your previously working system into new discussion on EE about how to recover a trashed Linux system.