Wednesday, 3 August 2016

Google: Linux Shell Style Guide

Shell Style Guide:



"Which Shell to Use :   Bash is the only shell scripting language permitted for executables.
Executables must start with #!/bin/bash and a minimum number of flags.

Use set to set shell options so that calling your script as bash does not break its functionality.

Restricting all executable shell scripts to bash gives us a consistent shell language that's installed on all our machines.

The only exception to this is where you're forced to by whatever you're coding for. One example of this is Solaris SVR4 packages which require plain Bourne shell for any scripts.



 When to use Shell

link
:  Shell should only be used for small utilities or simple wrapper scripts.
While shell scripting isn't a development language, it is used for writing various utility scripts throughout Google. This style guide is more a recognition of its use rather than a suggestion that it be used for widespread deployment.

Some guidelines:



  •  If you're mostly calling other utilities and are doing relatively little data manipulation, shell is an acceptable choice for the task. 
  • If performance matters, use something other than shell. 
  • If you find you need to use arrays for anything more than assignment of ${PIPESTATUS}, you should use Python. 
  • If you are writing a script that is more than 100 lines long, you should probably be writing it in Python instead. 




Bear in mind that scripts grow. Rewrite your script in another language early to avoid a time-consuming rewrite at a later date."



'via Blog this'

No comments:

Post a Comment