Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-12-2011, 09:28 AM   #1
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 Now I know that I am using bash of course and once the script runs i get a error which shows

./ line 1: !#/bin/bash: No such file or directory
PING ( 56(84) bytes of data.
64 bytes from ( icmp_req=1 ttl=52 time=52.1 ms
64 bytes from ( icmp_req=2 ttl=52 time=51.6 ms
64 bytes from ( icmp_req=3 ttl=52 time=51.6 ms
64 bytes from ( icmp_req=4 ttl=52 time=49.9 ms

--- 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:

./ 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 09:29 AM. Reason: correction of a typo in the second code tag
Old 12-12-2011, 09:42 AM   #2
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

bash will run your script.

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


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, 09:42 AM   #3
Senior Member
Registered: Aug 2009
Distribution: CentOS
Posts: 3,396

Rep: Reputation: 1485Reputation: 1485Reputation: 1485Reputation: 1485Reputation: 1485Reputation: 1485Reputation: 1485Reputation: 1485Reputation: 1485Reputation: 1485
That first line should begin with "#!", not "!#".
1 members found this post helpful.
Old 12-12-2011, 09:49 AM   #4
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
head -n3 | od -a
Assuming you have no spaces after #!/bin/bash, the first line should start with
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 09:50 AM.
Old 12-12-2011, 02:04 PM   #5
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


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 08:45 AM
veprory simple but frustrating for a newbie shell script question marigb Linux - Newbie 11 04-28-2004 12:11 PM
simple shell script question. strifel Programming 7 09-13-2003 01:44 PM
simple question on shell script gsbarry Linux - General 2 05-23-2003 04:09 AM
simple shell script question mathfeel Linux - General 12 03-06-2003 11:23 AM

All times are GMT -5. The time now is 01:57 PM.

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