Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the standard for documentation style in Bash scripts? [closed]

Tags:

I am currently writing a Bash script that has a number of functions in it and would like to add docs to make other team members understand what the point of the function is.

Is there a standard "style" for documenting Bash scripts and the functions it contains?

like image 378
linusthe3rd Avatar asked May 11 '12 14:05

linusthe3rd


People also ask

What do bash scripts end with?

One of the many known methods to exit a bash script while writing is the simple shortcut key, i.e., “Ctrl+X”. While at run time, you can exit the code using “Ctrl+Z”.

What does [[ ]] mean in bash?

The [[ ... ]] part allows to test a condition using operators. Think of it as an if statement. In your example, you're using the -s operator, which tests that the referenced file is not empty.

What file type are bash scripts?

Normally, a Bash script file has . sh extension to make it clear that it is a shell script file.

What are the proper file extensions for a bash shell script?

sh extension on your bash scripts.

What is the best bash style guide for beginners?

The best bash style guide I have come across is from Google. There is also some additional advice from the Chromium project. For learning bash, the Apple Developer Shell Scripting primer is excellent. Using a style guide for bash is rather sensible, as it is full of tricks and unexpected and difficult to diagnose quirks.

What is the best way to learn Bash shell scripting?

For learning bash, the Apple Developer Shell Scripting primer is excellent. Using a style guide for bash is rather sensible, as it is full of tricks and unexpected and difficult to diagnose quirks. Thus, if you follow the same style all the time, you should only fall for each of those tricks once.

What should be included on the Bash manual page?

The Bash manual page should be used as the definitive reference on shell behavior. An introduction to the shell. Some definitions used in the rest of this manual. The shell "building blocks". Commands that are a part of the shell. Variables used or set by Bash.

How do I browse the Bash documentation?

You're browsing the Bash documentation. To browse all docs, go to devdocs.io (or press esc ). 1.1 What is Bash? 1.2 What is a shell? 6.3.1 What is an Interactive Shell?


2 Answers

I do understand I'm adding an answer to an old question, but I feel the tooling has improved lately and would like to give additional suggestions in order to help out others who are viewing this question.

I have recently found TomDoc.sh, which uses TomDoc style comments in shell scripts. The tool provided can then extract information and generate markdown or plain text documents.

Other tools also exist. BashDoc is modeled after the JavaDoc syntax, supporting a variety of tags. With RoboDoc you embed a C-style comment in your Bash code and it extracts the necessary information. Lastly, Apple uses HeaderDoc for its shell scripting. All three of these have a suggested style for the comments that you write.

If you wish to annotate your code more than generate documentation, shocco.sh may be what you'd prefer. It doesn't have a specific format and is designed for you to see human-readable text describing the shell commands that you are running.

like image 140
fidian Avatar answered Dec 27 '22 15:12

fidian


Usually, I try to follow guidelines that are analog to the ones I use with other languages like C.

This includes a function header containing:

  • function name, short description and purpose
  • list of arguments and return values, with descriptions
  • list of all side effects (e.g., changes in variables or files)
like image 22
mouviciel Avatar answered Dec 27 '22 17:12

mouviciel