LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash coding standards (https://www.linuxquestions.org/questions/programming-9/bash-coding-standards-4175438516/)

catkin 11-24-2012 01:21 AM

bash coding standards
 
Are there any bash coding standards on the 'net or otherwise available? I can't find any and don't recall ever seeing any.

rosehosting.com 11-24-2012 02:45 AM

You can find some bash coding guidelines at: http://wiki.bash-hackers.org/scripting/style

Quote:

Originally Posted by catkin (Post 4835917)
Are there any bash coding standards on the 'net or otherwise available? I can't find any and don't recall ever seeing any.


fakie_flip 11-25-2012 12:37 AM

The standards it follows are those defined for POSIX sh. But it also has extensions in addition to that. A few things in bash are not 100% POSIX sh compliant, but bash can be invoked in a way that it is.

Quote:

Invoking Bash with the --posix option or stating set -o posix in a script causes Bash to conform very closely to the POSIX 1003.2 standard.
Here's some useful links from the topic at the bash channel on irc.

Topic for #bash is "FAQ: http://mywiki.wooledge.org/BashFAQ |
Guide: http://mywiki.wooledge.org/BashGuide | ref:
http://xrl.us/bhk9ww | http://wiki.bash-hackers.org/ | USE MORE
QUOTES!: http://www.grymoire.com/Unix/Quote.html | Scripts and
more: http://www.shelldorado.com/ | Bug mailing list:
http://tx0.org/3af | New official help mailing list:
http://tx0.org/31f | Devel branch: http://xrl.us/bmodjy"

steelneck 11-25-2012 10:19 AM

Advanced Bash-Scripting Guide can contain some useful info for you:

http://www.tldp.org/LDP/abs/html/index.html

catkin 11-26-2012 03:54 AM

Thanks rosehosting.com, that is exactly what I am looking for :)

Thanks fakie_flip but it is coding standards not language standards I am looking for :)

Thanks steelneck :) ABS does have "Chapter 35, Scripting With Style" but it has only one section: 35.1. Unofficial Shell Scripting Stylesheet and that looks like an early draft.

H_TeXMeX_H 11-26-2012 12:19 PM

You know, I don't like that style guide. However, I can't really provide a good style guide. In bash it's not too important, because it's mostly readable. You know maybe I'll write my own style guide and put it on a wiki somewhere.

catkin 11-27-2012 06:34 AM

That's the great thing about standards -- if you don't like them you can write your own :rolleyes:

Seriously, it's nice to have a starting point and I'm happy with most of the Bash Hackers Wiki's page.

Since the OP, I found bash "good practice" guides at the well known Greg's WIKI and at Hall of Tips. All good stuff.

A bash "coding standard", "style guide" or "good practice guide" could usefully also suggest some defensive commands:
Code:

    # Configure shell environment
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    export PATH=/usr/sbin:/sbin:/usr/bin:/bin
    IFS=$' \n\t'
    set -o nounset
    umask 0022

along with using readonly for "constants" and local to restrict variable scope in functions ...


All times are GMT -5. The time now is 01:57 AM.