Solved

Linux bash script execution problem

Posted on 2012-03-22
4
352 Views
Last Modified: 2012-03-23
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 ?
0
Comment
Question by:Los Angeles1
  • 2
4 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
Comment Utility
Your script contains carriage-return characters at the line ends.

Did you transfer it from Windows in text mode (instead of binary mode)?
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
Comment Utility
tr -d '\r' < net > net.tmp && mv net.tmp net
0
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
or just do
dos2unix net

Open in new window

0
 
LVL 8

Expert Comment

by:eager
Comment Utility
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.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now