?
Solved

shell scripting coding guidelines /checklist

Posted on 2015-01-05
7
Medium Priority
?
146 Views
Last Modified: 2015-02-09
Hi ,

Can you please share any coding guidelines / standards available for shell scripting ?

Thanks,
Magento
0
Comment
Question by:magento
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 40532911
Which shell?
0
 
LVL 5

Author Comment

by:magento
ID: 40532922
Ozo ,

I am planning to use BASH.

Thanks
0
 
LVL 1

Assisted Solution

by:jsaun
jsaun earned 2000 total points
ID: 40532943
There are some style guides out there that you can read.  Take the good parts, and have good reasons for what you disagree with.   Mostly check with your client or employer and see what they require.

My top tenets:

Make your code read like prose.  Long, descriptive variable names are more clear for others to understand when they come along years later to tweak your code.  This means never use a loop iterator named "i".  If you're looping over servers in a list, then do something like  
for currentServer  in $serverList

Plan it out before you start writing it.  Remember doing flowcharts in college?  It's still a good idea.  Diagrams help you make sensible functions, and help you discover corner cases before you're coding.

Have someone buddy check as you go along, and test frequently.  

Write your test cases before you write your code.

Here are some style guide links:

http://wiki.bash-hackers.org/scripting/style
https://google-styleguide.googlecode.com/svn/trunk/shell.xml
http://tldp.org/LDP/abs/html/scrstyle.html 

Cheers and good luck
0
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 
LVL 5

Author Comment

by:magento
ID: 40537207
Hello Jsaun,

Thanks for the ideas, i will follow it.
I am new here, can you please share knowledge on writing test cases ?

Thanks
0
 
LVL 1

Accepted Solution

by:
jsaun earned 2000 total points
ID: 40537247
If your script expects input, test it with invalid input (as well as valid).  Typos, nulls, negative numbers, spelling errors.

If your script connects to a resource, how does it behave if the resource is not available?

If your script might be called by a hacker, check for stuff like SQL injection.   The best rule is: only accept data you are expecting to see.  If the data looks bad, better to fail safe.

That sort of thing.

And in a related note:  write out lots of logging data.  Logs help you find and fix problems later.  If you want to get fancy, you can put a debug switch in and use that to turn off most of the logging later on, but rarely will you regret having good logs
0
 
LVL 5

Author Comment

by:magento
ID: 40539117
Exactly what i'm looking for . Thank you so much !!!
0
 
LVL 5

Author Closing Comment

by:magento
ID: 40597828
jsaun,Thanks again!!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question