Unix Shell Scripting Standards


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix Shell Scripting Standards
# 1  
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  
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  
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.

# 4  
Thanks a million 66IISW & cfajohnson for your replies, I will try & use the information you've sent on.
# 5  
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.

# 6  
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.
# 7  
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.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #729
Difficulty: Medium
BASIC stands for Basic All-purpose Symbolic Instruction Code.
True or False?

9 More Discussions You Might Find Interesting

1. Programming

unix Shell scripting

Hi All, need help to complete the automation but stuck at a perticular situation below is the code <code> fixed_function_name { code.... code.... variable_map= { a="/a" b="/b" c="/c" so on... } (7 Replies)
Discussion started by: yadavricky
7 Replies

2. Shell Programming and Scripting

UNIX Shell scripting

Hi, How to read .lst file line by line and while reading time it needs to copy the file into another file in unix shell script. could you please help in this issue. Thanks, Rami Reddy. (4 Replies)
Discussion started by: Rami Reddy
4 Replies

3. Shell Programming and Scripting

Need help in UNIX Shell Scripting

Requirement is :- 1. there will be daily monthly and on demad flat files coming in SourceDir folder in unix. I want that if daily files are copied in the folder then my script shd check that if files are copied and are correct then process to load files trigger otherwise send a mail to... (1 Reply)
Discussion started by: Ruchi A
1 Replies

4. UNIX for Dummies Questions & Answers

Unix Shell Scripting( Calling from Unix to PLSQL)

Hello Experts, I have the following questions to be discussed here at this esteemed discussion forum. I have two Excel sheets which contain Unix Commands llike creating directory the structure/ftp/Copy/Zip etc to basically create an environment. I need help in understanding some of... (1 Reply)
Discussion started by: faizsaadq
1 Replies

5. Shell Programming and Scripting

Secure coding standards for Shell Programming

Hi, Can anyone point me to Secure coding standards for shell programming guides, links etc etc... Thanks and regards, Vamsi K Surampalli. (2 Replies)
Discussion started by: vamsisurampalli
2 Replies

6. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

7. Programming

UNIX version standards

I'm new to UNIX programming. I'm used to starting my program's versions at 1.0, but I look at all the UNIX programs out there and see things like 0.000.1 or 3.3.000 and I'm wondering what these things really mean. Do people just type anything they feel in there? Are things in pre-release... (6 Replies)
Discussion started by: hirni
6 Replies

8. UNIX IEEE Std 1003.1-2001 (POSIX.1)

Link to the Open Group (UNIX Standards)

Click HERE to learn about The Single UNIX Specification, Version 3 Or: Here is another link to the UNIX IEEE Standard, an Open Group Technical Standard, Issue 7 Keywords UNIX® is a registered trademark of The Open Group (0 Replies)
Discussion started by: Neo
0 Replies

9. UNIX for Dummies Questions & Answers

Unix Coding Standards

Hi, I am looking for some coding standards for Unix Shell Scripting. Can anyone help me out in this? Regards, Himanshu (3 Replies)
Discussion started by: himanshu_s
3 Replies

Featured Tech Videos