LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 12-12-2011, 10:28 AM   #1
charging-ibis
Member
 
Registered: Dec 2011
Location: Columbus, OH
Distribution: Slackware 13.37
Posts: 38

Rep: Reputation: 0
Simple Shell Script Question


Hello this is my first time using this forum. And I hope to one day be able to to be in this section assisting others.

I have a simple question and it is regaurding the running the shell script. I made a simple test script to go to the Documents directory and then ping www.yahoo.com. Now I know that I am using bash of course and once the script runs i get a error which shows

Code:
./a-ping.sh: line 1: !#/bin/bash: No such file or directory
PING www.yahoo.com (209.191.122.70) 56(84) bytes of data.
64 bytes from ir1.fp.vip.mud.yahoo.com (209.191.122.70): icmp_req=1 ttl=52 time=52.1 ms
64 bytes from ir1.fp.vip.mud.yahoo.com (209.191.122.70): icmp_req=2 ttl=52 time=51.6 ms
64 bytes from ir1.fp.vip.mud.yahoo.com (209.191.122.70): icmp_req=3 ttl=52 time=51.6 ms
64 bytes from ir1.fp.vip.mud.yahoo.com (209.191.122.70): icmp_req=4 ttl=52 time=49.9 ms

--- www.yahoo.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 15249ms
rtt min/avg/max/mdev = 49.983/51.368/52.163/0.840 ms


So here is the issue i know that !#/bin/bash has to be included in the first line of the script right? But when I run the script I get this error:

Code:
./a-ping.sh: line 1: !#/bin/bash: No such file or directory
And yet the script executes as it should. And I have confirmed that 'bash' is in the ./bin subdirectory. May I get an explanation? Dose this message really matters? If so then I would like to know how, and what is the best solution to the problem. I would love to be enlightened on this. Thank you.

Last edited by charging-ibis; 12-12-2011 at 10:29 AM. Reason: correction of a typo in the second code tag
 
Old 12-12-2011, 10:42 AM   #2
l00
LQ Newbie
 
Registered: Dec 2011
Posts: 2

Rep: Reputation: Disabled
Hi. also first time user. if you delete that line and run bash with the name of your script as parameter

$ bash myscript.sh

bash will run your script.

the other way it to run it right away which you are doing.

./myscript.sh

your _current_ bash reads the contents (if the execute permission is set , see chmod) and reads the first line to see who is meant to be able to execute the following content of the file. the line is called a shebang (see wikipedia)

Please include waht you actually type in when you post pastes. including the content of your script is also useful to get the full context
 
Old 12-12-2011, 10:42 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,959

Rep: Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268
That first line should begin with "#!", not "!#".
 
1 members found this post helpful.
Old 12-12-2011, 10:49 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
In case there is a hidden character causing trouble, use this command
Code:
head -n3 a-ping.sh | od -a
Assuming you have no spaces after #!/bin/bash, the first line should start with
Code:
0000000   #   !   /   b   i   n   /   b   a   s   h  nl
If it does not, please post the output here.

EDIT: don't bother, rknichols has identified the problem.

Last edited by catkin; 12-12-2011 at 10:50 AM.
 
Old 12-12-2011, 03:04 PM   #5
charging-ibis
Member
 
Registered: Dec 2011
Location: Columbus, OH
Distribution: Slackware 13.37
Posts: 38

Original Poster
Rep: Reputation: 0
Reply: Thanks

thank you both of you all helpled. i learned something new and corrected my descrepency of !# when it was actually supposed to be #!. Thank your
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Simple Question? The 'DOT' in a shell script test spampig Linux - Newbie 2 02-21-2010 09:45 AM
veprory simple but frustrating for a newbie shell script question marigb Linux - Newbie 11 04-28-2004 01:11 PM
simple shell script question. strifel Programming 7 09-13-2003 02:44 PM
simple question on shell script gsbarry Linux - General 2 05-23-2003 05:09 AM
simple shell script question mathfeel Linux - General 12 03-06-2003 12:23 PM


All times are GMT -5. The time now is 08:55 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration