LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-03-2012, 08:17 AM   #1
Annielover
Member
 
Registered: May 2011
Location: Belgium
Distribution: Ubuntu Server Edition, Fedora 16
Posts: 90

Rep: Reputation: 8
#!/bin/bash ERROR


Hi all,

I successfully managed to run a bash/CGI test script, but my main index.sh script won't execute because of the following error:
Code:
./index: 1: #!/bin/bash: not found
What are all those strange letters in front of /bin/bash?? Something wrong with the encoding?

This is a working CGI/bash script:
Code:
#!/bin/bash
WHO=`who | gawk '{print $1}'`
echo "Content-type: text/html"
echo ""
echo "<html>"
echo "<head>"
echo "<title>system information for $(hostname -s)</title>"
echo "</head>"
echo "<body>"
echo "<h2>General system information for host $(hostname -s)</h2>"
echo "<h3>Users logged on:</h3>"
echo "<p>$WHO</p>"
echo "<h3>System uptime:</h3>"
echo "<p>$(uptime)</p>"
echo "</body>"
echo "</html>"
Code:
laurent@server:/home/www/cgi-bin$ sudo ./sysinfo
Content-type: text/html

<html>
<head>
<title>system information for server</title>
</head>
<body>
<h2>General system information for host server</h2>
<h3>Users logged on:</h3>
<p>laurent
laurent</p>
<h3>System uptime:</h3>
<p> 15:08:43 up 7 days,  5:40,  2 users,  load average: 1.67, 1.43, 1.26</p>
</body>
</html>


This doesn't work:
Code:
#!/bin/bash
UPTIME=`uptime`
HOST=`hostname -s`
echo 'Content-type: text/html'
echo ''
echo '<html xmlns="http://www.w3.org/1999/xhtml">'
echo '<head>'
echo '<meta name="keywords" content="" />'
echo '<meta name="description" content="" />'
echo '<title>Monitoring Center for $HOST | Overview</title>'
echo '<link href="http://fonts.googleapis.com/css?family=Arvo" rel="stylesheet" type="text/css" />'
echo '<link href="style.css" rel="stylesheet" type="text/css" media="screen" />'
echo '</head>'
etc ...
etc ...
Code:
laurent@server:/home/www/cgi-bin$ sudo ./index
./index: 1: #!/bin/bash: not found
Content-type: text/html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
etc ...
etc ...
Any advice? Thanks!
 
Old 07-03-2012, 09:26 AM   #2
montel
Member
 
Registered: Jun 2012
Location: Canada
Distribution: Ubuntu/Debian/CentOS
Posts: 45

Rep: Reputation: 19
I believe that may be a $PATH problem. Run:

echo $PATH

what does that return?
 
Old 07-03-2012, 10:07 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
So your saying that after the error the echoes are still working?

Also, why do the scripts need to be run with sudo?

Is 'index' executable?
 
Old 07-03-2012, 10:28 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Your problem is being caused by an initial BOM:

http://en.wikipedia.org/wiki/Byte_order_mark

The simplest fix is probably to just copy the visible text into a new file.
 
2 members found this post helpful.
Old 07-03-2012, 10:38 AM   #5
Annielover
Member
 
Registered: May 2011
Location: Belgium
Distribution: Ubuntu Server Edition, Fedora 16
Posts: 90

Original Poster
Rep: Reputation: 8
Quote:
Originally Posted by David the H. View Post
Your problem is being caused by an initial BOM:

http://en.wikipedia.org/wiki/Byte_order_mark

The simplest fix is probably to just copy the visible text into a new file.
That worked for me, thanks!
I just created a new file and started all over, now it works like charm.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
chroot: cannot run command `/bin/bash': Exec format error snakeo2 Linux - Newbie 6 09-28-2010 03:41 AM
chroot; /bin/bash error raj_hcl1986@rediffma Linux - Newbie 2 11-10-2008 09:24 AM
Error when starting up snort: bash:!/bin/sh/usr/local/bin/snort :Eent not found cynthia_thomas Linux - Software 1 11-11-2005 02:59 PM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 06:42 PM
linux command error message bash: /usr/bin/find: No such file or directory sundaram123 Linux - General 8 04-02-2002 07:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration