An example of a bash script with test blocks (2024)Here is a screenshot - click on it to enlarge: It shows a script that I use to convert a series of PDFs into an animated gif. It is explained, as a tool, in this section of one of my pages about Maxima. I don't write Bash code often, and I would never be able to remember what the tricks in red below do
without 1) links to the documentation and 2) examples. The links to the documentation appear right above that code in the screenshot - let me copy them here:
These links work much better in Emacs than in the browser. If you click on the `")' at the end of one of the `find-bashnode' links above you will see that it goes to a page of the Bash manual, but it "ignores the pos-spec-list"... while in Emacs the second link searches for the first occurrence of "${@:7}", as shown here: So that solves the first half of my problem - "1) links to the documentation". The second half of my problem - "2) examples" - is much trickier. For me it is much easier to test the individual functions in a bash script if it can be used both "as a library" and "as a script"; and the trick that lets it be used in both ways is an
at the end of the script - see here, or in this screenshot, that also shows its comments and a test block: Test:
|