My scrapbook about almost anything I stumble upon in my tech world. If you find anything useful don't forget to give thumbs-up :)


Monday, August 31, 2015

Linux Shell Scripting Best Practices

What is a script? 
A script is a set of commands, either in a file, or typed in at the command line, that perform multiple operations on a file or files.

How do they work? 
To run a file as a script, the file must have the execution bit set

Best Practices
¨     Writing clean code, using indents and using comments to explain parts of your code.
¨     Defining variables properly and avoid using unnecessary ones.
¨   Proper usage of functions. This would help edit, replace parts of the scripts easily without   proper functioning of the base script.
¨     Using log functions as when needed
¨     Putting usernames/passwords in scripts should be avoided.
¨     Hard-coding hostnames, files directory paths in a script should be avoided.
¨   The same form should be maintained throughout for the code. Inconsistent coding   styles make debugging a lot harder regardless of who's doing it.
¨     Proper documentation is very much needed.
¨  Proper testing needs to be done on Non-Production before implementing the scripts in a production environment.
¨     Generic scripts should have a common and understandable name.
¨    Understand the requirement and scope as where shell scripts can be implemented and where not.

No comments:

Post a Comment


The postings on this site are my own and don't necessarily represent IBM's or other companies positions, strategies or opinions. All content provided on this blog is for informational purposes and knowledge sharing only.
The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of his information.