View Single Post
Old Apr 7th, 2008, 12:14 AM   #10
opa6x57
Hmmmm ... Is there more??
 
opa6x57's Avatar
 
Join Date: Apr 2008
Location: Post Falls, ID
Posts: 15
Rep Power: 0 opa6x57 is on a distinguished road
Re: Starting to use Unix

Quote:
Originally Posted by sons_of_bitch View Post
why some of the scrip file is without the starting #!/bin/bash or any shell, and can straight away coding? what is the different between with starting #!/bin/bash or without the #!/bin/xxx in the starting script?

sorry i'm new in unix..

Thanks

If you are writing a script that you know, with 100% certainty, will always be run on a machine where the only available shell is the one you're using to write the script - then this line is completely optional.

If, however, there exists a possibility that some user will use a different shell - then you MUST specify the shell to be used for your script.

For example - if you use a script command that only exists in the /bin/csh shell - and your user happens to be using the /bin/sh shell - it is very likely that your script will fail. (I almost would guarantee failure in this instance...)

But, if you force your script to run in a specific shell using the !shebang then your script will function correctly.
__________________
Ken -
New to PFO ... but been dabbling in various versions of BASIC since highschool - circa 1973.

"Shouldn't the 'Air and Space' museum be empty?" - Dennis Miller
opa6x57 is offline   Reply With Quote