Shell Scripting Standards

  • Imran Quadri Syed

    SSC Veteran

    Points: 251

    Comments posted to this topic are about the item Shell Scripting Standards

  • fschreuder

    SSC Veteran

    Points: 289

    Must admit I only skimmed your article skeptically and was pleasantly surprised with it. Great overview of how and why you should script "by the rules". Usefull conventions, great example of layout and explanation.

    I did notice this typo; don't think it will work out :


    # Defining local Variable


    # echo the value in variable.

    echo $5


    Keep it up!

  • Chris Wooding

    SSCarpal Tunnel

    Points: 4334

    Good article. The only thing I'd question is having the revision history in the header; over time this can become very verbose and bloat the script considerably. All that information should be in the source control commit comments.

  • GeorgeCopeland


    Points: 6936

    Great article, I really liked it. I agree with keeping version history in source control not in the header.

  • Spiff


    Points: 7762

    Me three.  Having a revision history is pointless if you don’t have the history of previous versions to diff against.  All you know is something changed and you can’t reliably revert it, you’re always fixing forwards.

  • mosaic-287947

    Ten Centuries

    Points: 1042

    Something I also tend to do:

    If the script uses any hard-coded values (for example how many times to re-try after a likely failure, or the format definition of an output string) then declare them all in a block near the top of the script, for example just before/after verifying the input.

    This avoids hidden unnamed "magic" numbers or strings. In practice I found that this also makes it much easier to convert such a value into an argument should this become necessary.

    Also, when a change is needed, you do not have to touch the main body of the code, reducing the risk of introducing a bug

    • This reply was modified 4 months, 2 weeks ago by  mosaic-287947.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply