ksh and sh | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

ksh and sh

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-04-2007
Elidas Elidas is offline
Registered User
 
Join Date: May 2007
Last Activity: 17 March 2008, 4:17 AM EDT
Location: Madrid
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
ksh and sh

What is the difference between a script starting with:

#!/bin/ksh

and

#!/bin/sh


thanks
Sponsored Links
    #2  
Old 05-04-2007
anbu23's Avatar
anbu23 anbu23 is offline Forum Advisor  
Advisor
 
Join Date: Mar 2006
Last Activity: 17 September 2014, 3:10 AM EDT
Location: Bangalore,India
Posts: 2,089
Thanks: 12
Thanked 131 Times in 126 Posts
Quote:
Originally Posted by Elidas
What is the difference between a script starting with:

#!/bin/ksh

and

#!/bin/sh


thanks
ksh is korn shell.
Sh is bourne shell.

Script starting with #!/bin/ksh is executed by Korn shell
Script starting with #!/bin/sh is executed by Bourne shell
Sponsored Links
    #3  
Old 05-04-2007
Elidas Elidas is offline
Registered User
 
Join Date: May 2007
Last Activity: 17 March 2008, 4:17 AM EDT
Location: Madrid
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
ksh is korn shell.
Sh is bourne shell.
ok, and what is korn and bourne? it sounds like the very best friends one should have at unix (sorry I am a noob at unix)

The problem is that I have that simple script here:

Quote:
#!/bin/ksh
rem Filename: sysdba.sh
echo "Users that can startup, shutdown and admin Oracle Databases:"
echo
grep `grep ^dba /etc/group | cut -d: -f3` /etc/passwd
and I am not sure if I have to put ksh or sh in the first line.
    #4  
Old 05-04-2007
johnf johnf is offline
Registered User
 
Join Date: May 2006
Last Activity: 10 April 2014, 6:14 AM EDT
Location: England
Posts: 406
Thanks: 7
Thanked 7 Times in 7 Posts
Quote:
Originally Posted by Elidas
ok, and what is korn and bourne? it sounds like the very best friends one should have at unix (sorry I am a noob at unix)

The problem is that I have that simple script here:



and I am not sure if I have to put ksh or sh in the first line.
Which first line do you mean? The delaration at the top means this script will run as a ksh script. The script definition effects the syntax in the script.
Sponsored Links
    #5  
Old 05-04-2007
Elidas Elidas is offline
Registered User
 
Join Date: May 2007
Last Activity: 17 March 2008, 4:17 AM EDT
Location: Madrid
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
The file is sysdba.sh and the first line of the file is #!/bin/ksh
Sponsored Links
    #6  
Old 05-04-2007
TinWalrus TinWalrus is offline
Registered User
 
Join Date: May 2007
Last Activity: 7 November 2013, 8:11 AM EST
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
the #!/bin/ksh at the top of the file define what the following commands in the script use as an interpreter, in this case /bin/ksh (the korn shell)

you can put practically any interpretive shell command there, i.e.

#!/usr/bin/awk for awk
#!/usr/bin/perl for perl

and so on. putting a ':' there will mean use the default shell

the difference between sh and ksh (bourne and korn) is mostly functionality. i.e. ksh has variable substitutions, dimensioned arrays, etc
Sponsored Links
    #7  
Old 05-07-2007
lazytech lazytech is offline
Registered User
 
Join Date: Nov 2006
Last Activity: 30 December 2013, 11:19 AM EST
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Also good to know is anything written for bourne shell can run in korn shell. As TinWalrus stated, korn shell has more functionality.

Now the #! ( pronounced Shebang ) line of the script just tells the script what shell to use when executing. So say you use bourne shell and have a script that uses functionality of korn shell you could run the script in your bourne shell provided you have included the line #!/usr/bin/ksh
If you didn't include this, your script might return an error.

( Thanks for the correction reborg. )

Last edited by lazytech; 05-07-2007 at 11:24 AM.. Reason: Incorrect statement. Thanks for the catch reborg!
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes



All times are GMT -4. The time now is 06:21 AM.