The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need your Help on Unix Shell Scripting......... vinayraj UNIX for Advanced & Expert Users 5 02-08-2008 07:00 AM
Shell Scripting (Unix) tt1ect Shell Programming and Scripting 3 04-15-2007 09:15 AM
Unix shell scripting Maruthi Kunnuru Shell Programming and Scripting 4 05-23-2006 12:19 AM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 08:12 AM
Unix shell scripting la_burton UNIX for Dummies Questions & Answers 6 10-22-2004 11:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-26-2007
janmolby janmolby is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 2
Unix Shell Scripting Standards

Would anyone have details of pre-existing Unix shell scripting standards. I've been asked to prepare a document outlining standards when writing korn shell scripts & don't really know where to start. Thanks.
  #2 (permalink)  
Old 03-26-2007
66IISW's Avatar
66IISW 66IISW is offline
Registered User
  
 

Join Date: Feb 2007
Location: Scottsdale, Arizona
Posts: 2
Below are a couple of rules to get you started. Good luck with it...

All scripts will begin with #!/bin/ksh to ensure we get ksh results however script is invoked.

All scripts requiring input parameters will contain code to ensure the user has entered an appropriate number of parameters, else the script will display a proper syntax message explaining correct use of the command.

All scripts which create temporary files will create these files in the /tmp directory with the process id as part of the data set name (i.e. /tmp/$$.somename), and will employ the trap command to cleanup all /tmp files on completion, example here:

trap "rm -f /tmp/$$.* 2>/dev/null; exit 2" 1 2 3 9 15
trap "rm -f /tmp/$$.* 2>/dev/null; exit 0" 0

All scripts requiring SAS code to be generated, will use the << functionality to generate the required SAS code dynamically into a /tmp data set.
  #3 (permalink)  
Old 03-29-2007
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by 66IISW
Below are a couple of rules to get you started. Good luck with it...

All scripts will begin with #!/bin/ksh to ensure we get ksh results however script is invoked.

It will not get ksh results if ksh is not in /bin.

It will not get ksh results if it is started with:
Code:
sh /path/to script
Or (if your shell isn't ksh):
Code:
. /path/to script
It may not work if the ksh in /bin is pdksh and you need ksh93.

  #4 (permalink)  
Old 03-29-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
It will probably work if /bin/ksh is a link to zsh. This is common on a lot of our Linux boxes here.

What CFA J & I are telling you is that the best practice is to use the magic at the top of your script. But you do not have guarantees what shell you will invoke, especially when the code is ported. So, on the internet, that becomes very true - like porting into a black hole. So, #!/bin/ksh may not mean what you think.

Consider reading the link in the above post if you're confused about standards.
  #5 (permalink)  
Old 03-29-2007
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by jim mcnamara
It will probably work if /bin/ksh is a link to zsh. This is common on a lot of our Linux boxes here.

On most Linux distros I've used, /bin/ksh is pdksh, which differs from the standard AT&T ksh in some important respects.
Quote:
What CFA J & I are telling you is that the best practice is to use the magic at the top of your script.

Actually, I am not saying that. A shebang is usually unnecessary, and reduces the portablility of a script.
  #6 (permalink)  
Old 03-28-2007
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by janmolby
Would anyone have details of pre-existing Unix shell scripting standards. I've been asked to prepare a document outlining standards when writing korn shell scripts & don't really know where to start. Thanks.

The Korn shell will run all scripts that conform to the POSIX standard for the shell. By writing scripts that conform to the standard, you will also be able to run them with other shells if that should ever be needed.

For more information see the standard at http://www.opengroup.org/onlinepubs/.../contents.html.

  #7 (permalink)  
Old 03-29-2007
janmolby janmolby is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 2
Thanks a million 66IISW & cfajohnson for your replies, I will try & use the information you've sent on.
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:43 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0