LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-24-2012, 01:21 AM   #1
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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.
 
Old 11-24-2012, 02:45 AM   #2
rosehosting.com
Member
 
Registered: Jun 2012
Location: Missouri, USA
Posts: 236

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

Quote:
Originally Posted by catkin View Post
Are there any bash coding standards on the 'net or otherwise available? I can't find any and don't recall ever seeing any.
 
1 members found this post helpful.
Old 11-25-2012, 12:37 AM   #3
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495

Rep: Reputation: 85
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"

Last edited by fakie_flip; 11-25-2012 at 12:39 AM.
 
Old 11-25-2012, 10:19 AM   #4
steelneck
Member
 
Registered: Nov 2005
Distribution: Slackware, Arch
Posts: 43

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

http://www.tldp.org/LDP/abs/html/index.html
 
Old 11-26-2012, 03:54 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578

Original Poster
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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.
 
Old 11-26-2012, 12:19 PM   #6
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
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.
 
Old 11-27-2012, 06:34 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578

Original Poster
Blog Entries: 31

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

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 ...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding an computer Artificial Intelligence using BASH? patrick295767 Programming 8 09-22-2012 02:49 PM
Bash awk coding loop rafir Linux - Newbie 12 04-12-2012 03:18 AM
ease bash/sh coding: Has someone right(,), left(,), and len(,) scripts for /usr/bin ? frenchn00b Programming 12 04-23-2009 02:33 PM
bash coding stocky021 Programming 3 11-01-2007 07:44 AM
Bash Coding Help neoific Linux - Software 1 11-11-2004 07:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration