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. 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
I always execute shell scripts without the sh at the beginning.
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..
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)
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)
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)
*** 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)
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)
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)
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)