Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Linux bash script execution problem

Posted on 2012-03-22
4
Medium Priority
?
368 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 2000 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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

722 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