Review your favorite Linux distribution.
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 07-02-2004, 11:19 PM   #1
Registered: Dec 2003
Distribution: RH8.0
Posts: 30

Rep: Reputation: 15
bash script, line1 #!/bin/sh - what does it mean?

The script, that came with the orion appserver, fails as follows:

[root@wynnserv orionServer]# ./ start
-bash: line 1: ./ No such file or directory

The first line of contains:


What does this syntax mean? - it looks like a comment to me.

I've scoured my reference material (including O'reily 'learning the bash shell') with
no explanation of why so many scripts start with '#!<path>'.

I'm running RH8

I presume the script is OK and that I'm doing something wrong elsewhere,
but not knowing what the diagnosed line is supposed to do, am confused.

Old 07-02-2004, 11:39 PM   #2
Registered: Feb 2004
Posts: 467

Rep: Reputation: 30
Let's look at this shell script. The first line, ``#!/bin/sh'', identifies the file as a shell script, and tells the shell how to execute the script. It instructs the shell to pass the script to /bin/sh for execution, where /bin/sh is the shell program itself. Why is this important? On most UNIX systems, /bin/sh is a Bourne-type shell, such as Bash. By forcing the shell script to run using /bin/sh, we are ensuring that the script will run under a Bourne-syntax shell (instead of, say, a C shell). This will cause your script to run using the Bourne syntax even if you use Tcsh (or another C shell) as your login shell.
Old 07-02-2004, 11:42 PM   #3
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
The #!/bin/bash tells the kernel which shell to use to run the script.
If it was a perl script, the first line would be '#!/usr/bin/perl'

Is the partition the file located in use the -noexec mount option in the /etc/fstab file? For example, you may not be able to execute the script off a CD. Some directories may be mounted with the -noexec option such as external USB drives. This can also be a security precaution on other partitions with global write access, like /tmp and /var. (The principle of least access)

Is executable? ( ls -l ./ )

Does the system use bash? If so what does, 'which sh' show. Probably '/bin/sh' with /bin/sh being a link to /bin/bash.

Some features of linux can be tricky to figure out. Such as if you are the owner of the file, but the owner permissions are cleared, you will not be able to access the file even if you have group permissions!

Last edited by jschiwal; 07-02-2004 at 11:47 PM.
Old 07-03-2004, 12:39 AM   #4
Senior Member
Registered: Nov 2002
Location: pikes peak
Distribution: Slackware, LFS
Posts: 2,577

Rep: Reputation: 48
Re: bash script, line1 #!/bin/sh - what does it mean?

Originally posted by ombill

The first line of contains:


What does this syntax mean? - it looks like a comment to me.

The sha-bang ( #!) at the head of a script tells your system that this file
is a set of commands to be fed to the command interpreter indicated. The #!
is actually a two-byte [4] "magic number", a special marker that designates a
file type, or in this case an executable shell script (see man magic for more
details on this fascinating topic). Immediately following the sha-bang is a
path name. This is the path to the program that interprets the commands in
the script, whether it be a shell, a programming language, or a utility. This
command interpreter then executes the commands in the script, starting at the
top (line 1 of the script), ignoring comments. [5]

#!/bin/sed -f
#!/usr/awk -f

Each of the above script header lines calls a different command interpreter,
be it /bin/sh, the default shell (bash in a Linux system) or otherwise. [6]
Using #!/bin/sh, the default Bourne shell in most commercial variants of
Unix, makes the script portable to non-Linux machines, though you may have to
sacrifice a few Bash-specific features. The script will, however, conform to
the POSIX [7] sh standard.

Note that the path given at the "sha-bang" must be correct, otherwise an
error message -- usually "Command not found" -- will be the only result of
running the script.
this is from the Advanced bash scripting guide............which can be
found at the Linux documentation project ................
Old 07-03-2004, 09:46 AM   #5
LQ Addict
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
Re: bash script, line1 #!/bin/sh - what does it mean?

Originally posted by ombill
The script, that came with the orion appserver, fails as follows:

[root@wynnserv orionServer]# ./ start
-bash: line 1: ./ No such file or directory

The first line of contains:

The first line in the file is not your problem. If it were, then the error you got would be something like "bad interpreter". Additionally, we know you have Bash, because your error is sent from Bash (bash: line 1: ./ No such file or directory).
There's apparently something messed up with the first line following the #! : ./
It's trying to run from the current directory.
My guess is that you are not running the script from within the proper directory (the one which contains I suggest you either change that line to include the path to, or cd into that directory to run the script....or put "cd /path/to/orion/directory" as the first line of the script.
Old 07-05-2004, 11:38 AM   #6
Registered: Dec 2003
Distribution: RH8.0
Posts: 30

Original Poster
Rep: Reputation: 15
Lightbulb Thanks

Thank you all for your replies, especially for pointing me to man magic. My
basic question is answered. and with the list of errors I may be making, I can
probably move forward.

Long live !



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
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
Change /bin/bash to /bin/zsh Smokey Slackware 12 07-14-2004 01:06 AM
script #!/bin/bash, problem with space in file names existent Linux - General 3 06-17-2004 08:13 AM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 06:42 PM
bin/bash:usr/bin/lpr NO SUCH FILE OR DIRECTORY Adibe_Hamm Linux - Newbie 3 10-14-2003 02:30 AM

All times are GMT -5. The time now is 09:35 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