LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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-2004, 12:19 AM   #1
ombill
Member
 
Registered: Dec 2003
Distribution: RH8.0
Posts: 30

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


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

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

The first line of orion.sh contains:

#!/bin/sh

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.

Bill.
 
Old 07-03-2004, 12:39 AM   #2
comp12345
Member
 
Registered: Feb 2004
Posts: 467

Rep: Reputation: 30
Quote:
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.
http://www.ictp.trieste.it/~radionet...LL/NODE150.HTM
 
Old 07-03-2004, 12:42 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
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 orion.sh executable? ( ls -l ./orion.sh )

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-03-2004 at 12:47 AM.
 
Old 07-03-2004, 01:39 AM   #4
320mb
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?

Quote:
Originally posted by ombill


The first line of orion.sh contains:

#!/bin/sh

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


Quote:
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/sh
#!/bin/bash
#!/usr/bin/perl
#!/usr/bin/tcl
#!/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, 10:46 AM   #5
mikshaw
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?

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

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

The first line of orion.sh contains:

#!/bin/sh
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: ./orion.sh: No such file or directory).
There's apparently something messed up with the first line following the #! : ./orion.sh
It's trying to run orion.sh from the current directory.
My guess is that you are not running the script from within the proper directory (the one which contains orion.sh). I suggest you either change that line to include the path to orion.sh, 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, 12:38 PM   #6
ombill
Member
 
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 www.linuxquestions.org !

Bill.
 
  


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
Error when starting up snort: bash:!/bin/sh/usr/local/bin/snort :Eent not found cynthia_thomas Linux - Software 1 11-11-2005 03:59 PM
Change /bin/bash to /bin/zsh Smokey Slackware 12 07-14-2004 02:06 AM
script #!/bin/bash, problem with space in file names existent Linux - General 3 06-17-2004 09:13 AM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 07:42 PM
bin/bash:usr/bin/lpr NO SUCH FILE OR DIRECTORY Adibe_Hamm Linux - Newbie 3 10-14-2003 03:30 AM


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