The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 05-04-2007
Registered User
 

Join Date: May 2007
Location: Madrid
Posts: 3
ksh and sh

What is the difference between a script starting with:

#!/bin/ksh

and

#!/bin/sh


thanks
Reply With Quote
Forum Sponsor
  #2  
Old 05-04-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
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
Reply With Quote
  #3  
Old 05-04-2007
Registered User
 

Join Date: May 2007
Location: Madrid
Posts: 3
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.
Reply With Quote
  #4  
Old 05-04-2007
Registered User
 

Join Date: May 2006
Location: England
Posts: 265
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.
Reply With Quote
  #5  
Old 05-04-2007
Registered User
 

Join Date: May 2007
Location: Madrid
Posts: 3
The file is sysdba.sh and the first line of the file is #!/bin/ksh
Reply With Quote
  #6  
Old 05-04-2007
Registered User
 

Join Date: May 2007
Posts: 27
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
Reply With Quote
  #7  
Old 05-07-2007
Registered User
 

Join Date: Nov 2006
Posts: 39
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 08:24 AM. Reason: Incorrect statement. Thanks for the catch reborg!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0