Solved

Linux bash script execution problem

Posted on 2012-03-22
4
360 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
ID: 37754449
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
ID: 37754500
tr -d '\r' < net > net.tmp && mv net.tmp net
0
 
LVL 48

Expert Comment

by:Tintin
ID: 37755183
or just do
dos2unix net

Open in new window

0
 
LVL 8

Expert Comment

by:eager
ID: 37758677
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

785 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