Solved

Linux bash script execution problem

Posted on 2012-03-22
4
366 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
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 …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

724 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