Programming guidelines and style

Hello all,

I would like to know if there is a generally accepted unix shell programming Guideline?

Do you have any idea where to find this?

There are a lot of programming Guidelines to find over Google, but is there one who is generally accepted?

Hi.

This is a meta-answer for shell coding.

1) Write however you want, then run your code through a semantic and syntax checker:

shellcheck      analyse shell scripts (man)
Path    : /usr/bin/shellcheck
Version : ShellCheck - shell script analysis tool
Type    : ELF 64-bit LSB executable, x86-64, version 1 (SYSV ...)
Help    : probably available with -h
Repo    : Debian 8.8 (jessie) 
Home    : http://hackage.haskell.org/package/ShellCheck (pm)

As you progress, you can skip this as the first step, and go right to testing, coming back if your code fails.

then through a beautifier (which could easily apply to all languages):

beautysh        Tidy bash scripts, written in python3. (what)
Path    : ~/bin/beautysh
Version : - ( local: RepRev 1.4, ~/bin/beautysh, 2016-03-31 )
Length  : 174 lines
Type    : Python script, ASCII text executable
Shebang : #!/usr/bin/env python3
Home    : https://github.com/bemeurer/beautysh (doc)
Modules : (for python codes)
  re
  sys

2) Shell (as a programming language for more than trivial scripting) is dead. Perl rules in its place (though it is now being strongly challenged by Python). -- Basic Linux and Unix bibliography , especailly parts:

a) Books on Shell, Script, and Web Programming

b) Good Programming Style

Best wishes ... cheers, drl

Hi drl,

thanks for your explanations... :slight_smile:

Shell programming is only for small Problems, for further things I would also take Python... but sometimes it is more comfortable to do some things with the os-shell than to write a Python-Script - sometimes I Need it in an Environment where a lot of People only have know-how it Shell Scripting. Therfor its not possible to take another language...

And my question Targets to the Point, if there is - for UNIX-Shell-Scripting - something like the PEPs in Python?

Hi.

Many people refer to the Linux Documentation Project, tldp, page on bash . In there you will find Unofficial Shell Scripting Stylesheet

However, if:

Perhaps you should be asking for advice on that problem.

Best wishes ... cheers, drl