Sponsored Content
Full Discussion: Scripts without shebang
Top Forums Shell Programming and Scripting Scripts without shebang Post 302694819 by Corona688 on Friday 31st of August 2012 12:39:44 PM
Old 08-31-2012
Quote:
Originally Posted by kraljic
Thank you Alister. Thanks everyone.

I have 4 quick questions:

Question 1.

According to Wikipedia /bin/sh means Bourne shell . Is that Right?
Yes.

Quote:
Question2.
So, in Solaris 10, RHEL Version5, version 6, AIX version 6, 7 , if i forget to add shebang to a script , will the script be executed using Bourne shell ?
Yes. Anything calling itself UNIX will have a Bourne shell available by default. Even on systems where c-shell is popular, Bourne is still available, because too many system things depend on it to exclude it. You could get more than you asked for -- BASH or DASH on Linux for instance -- but you will at least get generic Bourne features.

On Solaris you might get an extremely old pre-POSIX Bourne, to the point it doesn't understand $(this) syntax, only `backticks`, so if you forget the shebang, you might not get everything you need.
Quote:
Question3.
Regarding CarloM's post on sourcing . /path/to/script.sh
I have used sourcing only to set environmental variables in the current shell. Can sourcing be used to execute shell scripts as well?
Yes, entire shell scripts can be run. You could make an environment script that sets different variables for different users, for instance. Or an entire script of any purpose.

Note that the effect of exit is to make the shell quit. If it's running in a separate shell, it makes that shell quit. If it's running in your shell, it makes your shell quit. Smilie If you want a sourced script to exit without killing your terminal, use return instead.
Quote:
Question4.
I have noticed that some people execute shell scripts by putting sh at the beginning like

Code:
sh /path/to/myscript.sh

I always execute shell scripts without the sh at the beginning.

Code:
/path/to/script.sh

Which is recommended ?
Like said above, sh scriptname ignores the shebang, forcing it to use sh no matter what. What if it actually needs a full-fledged BASH or KSH shell, or something weirder like csh? sh scriptname wouldn't work. So I consider it best to let the shebang decide which interpreter to use.

This is a point of debate, however. There's arguments both ways.

Last edited by Corona688; 08-31-2012 at 01:46 PM..
This User Gave Thanks to Corona688 For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shebang

Hi, I am currently writing BASH shell scripts. I am using BASH on a Powerbook G4 running Leopard. Could somebody please explain the difference between #!/bin/bash and #!/bin/sh? I have been using the latter (#!/bin/sh), and things have been working fine. But is that the correct one to use... (9 Replies)
Discussion started by: msb65
9 Replies

2. Shell Programming and Scripting

Doubt in shebang line!!

Do we need to include the exclamatory mark in the shebang line??:confused: What if we dont include it??:eek: Actually what shebang line implies when we run a script?? shebang line--> #!/bin/ksh :p (6 Replies)
Discussion started by: nohup
6 Replies

3. Shell Programming and Scripting

Relacing the shebang line of a file

Can any one tell me how to replace a shebang line of a file using sed? Eg: If a file contains the following shebang line #!C:/InstantRails/ruby/bin/ruby I would like to replace it with #!/usr/local/bin/ruby The shebang line of the file can be obtained from the command cat... (3 Replies)
Discussion started by: linuxnewbe
3 Replies

4. Shell Programming and Scripting

Multiple shebang lines

*** EDIT: I found something close to my solution under an IIS 7 Module Handle.***** (Non-Homework question, simply an ease of use one) Odd question here and maybe its my newness to cgi/Perl, but is it possible to have 2 shebang lines? I write an test a ton of my homework code on my windows... (1 Reply)
Discussion started by: sennex
1 Replies

5. Shell Programming and Scripting

The Shebang!

Hi, I always thought that #!/usr/bin/ksh means that the script would be executed in korn shell i.e. when we'll execute the script with this line as the very first line then the shell spawns a korn shell (in this case as we are using #!/usr/bin/ksh ) and the script gets executed. But I am... (7 Replies)
Discussion started by: dips_ag
7 Replies

6. Shell Programming and Scripting

Hyphen char after shebang notation

Hi, I have a trivial question to ask, I am seeing in some shell scripts the '-' (hyphen) character following the first line of shell script (i.e) the shebang notation as follows: #!/bin/sh - #! /bin/bash - what does the hyphen signify? What will happen if it is not given explicitly? (2 Replies)
Discussion started by: royalibrahim
2 Replies

7. Shell Programming and Scripting

Shebang

If i am not using #! in my script. By default where will be my script running? (6 Replies)
Discussion started by: Kochu77
6 Replies

8. Shell Programming and Scripting

csh shebang query

What does the "-f" mean in following interpreter code #!/bin/csh -f Thank you (2 Replies)
Discussion started by: animesharma
2 Replies

9. Shell Programming and Scripting

Necessity of shebang line

Hi , I know about the shebang line in shell scripting. Just want to know whether is there any difference in execution of the program by keeping and not keeping the shebang line. Because without shebang line also the script is working. correct me if am wrong. Any help on this will be helpful (5 Replies)
Discussion started by: rogerben
5 Replies
All times are GMT -4. The time now is 05:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy