shell-api
In a nutshell
shell-api is:
-
a library of human-readable bash functions organized as modules
-
a framework for building efficient, scalable, distributable bash apps (Debian package)
-
Genapp, a tool for generating ready-to-go bash app skeletons
-
weak system dependencies (standard linux tools)
Disclaimer
Release history
| Release tag | Revision | Log |
|---|---|---|
R1.1.3 |
188 |
Release coming along with arcv 1.2.1 |
R1.1.2 |
168 |
Release coming along with arcv 1.2.0 |
R1.1.1 |
107 |
Release coming with hot fix for arcv 1.0.1 |
R1.1.0 |
100 |
First release officially used by an external tool , i.e. arcv revision control tool |
R1.0.0 |
20 |
First release |
Installation
Installing the package shell-api_1.1-3_amd64.deb for example will be installed in /usr/bin/shell-api-1.1-3/.
wget https://slashetc.fr/download/shell-api_1.1-1_amd64.deb
sudo dpkg -i shell-api_1.1-1_amd64.deb
# Sample, select the target installation folder and desired version
wget https://slashetc.fr/download/shell-api_1.1-1.zip
unzip shell-api_1.1-1.zip
The following table lists all the available versions. You can also click on the link to download instead of using wget:
| Debian Package | Zip | Creation time |
|---|---|---|
2026-09-07 00:33:03 +02 CEST |
||
2026-08-28 23:24:51 +02 CEST |
||
2026-07-26 12:03:48 +02 CEST |
||
2026-07-23 22:05:29 +02 CEST |
||
2026-05-20 |
Bash modules
Outline
The co-related functionalities are grouped into modules , i.e separate, independent bash source files. The list of functions are gathered at the end of the document.
| Module file | Macro function |
|---|---|
shell-api-core.sh |
|
shell-api-dev.sh |
|
shell-api-multimedia.sh |
|
shell-api-net.sh |
|
shell-api-packing.sh |
|
shell-api-sys.sh |
|
shell-api-yaml.sh |
|
shell-api-xslt.sh |
|
shell-api-selftest.sh |
|
shell-api-yaml.sh
The module shell-api-yaml.sh contains a mix of 2 APIs:
-
a set of functions used to manipulate YAML file with
yq. Basically each function call, requires to launchyq. This is suited for rare and sporadic use, unavoidable for the cases where the other inhouse API is not capable of performing the operation -
a set of functions to support very fast read-in of YAML data, whereby all data are read into a bash map all at once.
| The fast inhouse API does not support all YAML syntax and is not capable of writing YAML content. |
The inhouse YAML API is mainly achieved by calling YAML__setFile "yourfilepath" true and then invoking YAML__get "youryamlkey" yourvariable
|
The reason of the inhouse API is not only about speed. There are actually 2 versions |
Framework features
Foreword - Practical learning from examples
The following section documents some few typical framework features supplied by the library. There’s also an API documentation. However, some parts of it are still lacking.
As complement, it might be useful to check actual implementations relying on it, for example, the tools sumo, arc and shotplan, which are readable bash scripts.
Instant step-in
An app generated with Genapp app skeketon generator enables an instant step-in as follows:
-
Implement the app-specific behavior in the
[…]__main()function -
Add options in the
[…]__options.shfiles.
Single dash '-' are for any one-letter option, with an optional value
Double dashes -- are for multi-letter option names, optionally followed by '=' and a value
Dashless value can also be used, typically for commands
-
For multiple dashless arguments which positions are relevant, adapt
[…]__parseArgsHandleOptionLessArg()rather than using the options file. -
Implement the checks related to the parsed options and arguments inside
[…]__parseArgs() -
Implement
[…]__cleanup()for system signals handling, if necessary -
Customize
[…]__loadDep()to manage custom dependencies, if necessary
Loading a module (sourcing)
A module is loaded (sourced) using the following syntax, e.g. here loading module shell-api-dev.sh:
eval $_loadm<<<'shell-api-dev.sh'
Basically it "sources" the script into the current one, additionally:
-
it ensures the file is not sourced multiple times
-
sets internal variable
SHELL_SRC_NAMEto the loaded file for all the timespan the module is being sourced.
Loading a source file of the same app project (sourcing)
Any other source script part of the app project, i.e. located below the source directory, can be loaded (sourced) using the following syntax, e.g. here the loading of source file arcv__vars.sh of the sumo project can be loaded as follows:
eval $_loada<<<'arcv__vars.sh'
This is the equivalent of the following which is less convenient to use:
source "${ARCV__VARS["MYDIR"]}/arcv__vars.sh"
Managed configuration
By default, a configuration file is at the app’s disposal, located in the .config folder of the user’s home directory (letter case is relevant):
$HOME/.config/<Appname>/<appname>.yml
If this file does not exist, a default one is created from the default configuration file generated along with the app (.yml extension) upon first launch.
At startup, the library automatically loads the configuration data and stores it in the bash map named <APPNAME>__VARS[].
The bash map key is the uppercased YAML key where spaces are replaced with underscores. The following examples shows how the read data are mapped:
The configuration line will result in the execution of the following during app initialization:
| Configuration file line in <appname>.yml | Code executed at loading |
|---|---|
|
|
The accepted format is here specifically a very restricted subset YAML syntax. Only basic pairs key: value are accepted. If a more complex configuration is required and may have to be put under configuration management, a rule of thumb is to define a configuration parameter in $HOME/.config/<Appname>/<appname>.yml giving the path to the actual app configuration, which may then be YAML or any other format required by the specific app.
|
Logging
A basic logging API is available. The generated logs are plain text and the log file is located in the .local folder of the user’s home directory (letter case is relevant):
$HOME/.local/<appname>/log.txt
At the moment, it will be endless growing and survive over successive runs.
Logging levels
There are 4 types of messages which are highlighted with different colors when also displayed on the terminal:
| Message type | Console output | color |
|---|---|---|
Informational messages |
standard output (stdout) |
none |
Important Informational messages |
standard output (stdout) |
blue |
Warning messages |
standard error output (stderr) |
yellow |
Error messages |
standard error output (stderr) |
red |
Debug messages |
standard error output (stderr) |
green |
For apps generated by Genapp app skeketon generator, the debug messages can be activated with the --debug option. This should be reserved for development and debugging purposes.
|
On-the-fly installation of system packages
If the app which is developped from the generated skeleton requires additional system packages, those can be programmed to be installed automatically on-the-fly, anywhere where required in the source code, by using the built-in _loadDep function.
_loadDep "lsb-release"
_loadDep "gawk@gawk" # awk
_loadDep "parted@parted" # parted
_loadDep "gdisk@gdisk" # gdisk
The prerequisite is that the app implements the callback […]__loadDep(). An app generated with Genapp app skeketon generator contains by default the following callback, which attempts to load the package via APT:
<Appname>__loadDep()
{
if ! Args__checkCount ${FUNCNAME[0]} 1 "$#" "Usage: <dependency name>"; then return 1; fi
# By default, attempts to install an APT package of the passed name
Pkg__install "$1" "" apt
}
Other package types can be installed, see the following sample code:
Pkg__install function # Downloads the package from the passed URL and installs directly via dpkg -i
Pkg__install "veracrypt-console" "1.23.0" dpkg "$URL"
# Installs via snap
Pkg__install "yq" "" snap
# Installs via gem
Pkg__install "yq" "" gem
The @ writing is optional, it gives an hint of which tool part of the package is actually used.
|
|
For optimisation purposes, automatically installed packages are tracked in the cache file
|
System signals handling
By default, the libray catches the system signals and invokes the user-defined […]__cleanup() callback, if any, passing on the caught exit code as argument.
Managed temporary files and folders
Temporary files or folders created with File__createTempFile and File__createTempDir can be automatically cleaned up at application exit by calling File__deleteAllTempItems.
Managed XSLT transformations
XSLT__transformToText and XSLT__modifyXML eases XSLT transformation with xsltproc :
-
temporary XSLT file creation from passed arguments
-
automatic formatting of parameter arguments for the
xsltproccall -
automatic generation of XSLT parameters arguments for the
xsltproc -
generation of the suitable XSLT header including identity transform if necessary/
So that the developer can only focus on the core transformation rules;
Genapp app skeketon generator
The Genapp tool generates ready-to-go bash app skeletons.
It also generates a Makefile to perform the following operation:
|
Make and install man page for the tool |
|
Generate both a Debian and a zip package according to VERSION.txt |
Managed shell-api Dependency
A symbolic link to the shell api library from which Genapp app skeketon generator was executed will be set up inside the generated app. The user is then free to manage the link, e.g. by changing it to another installed version.
The generated Makefile enables to manage the dependency transparently as follows:
-
The dependency version of shell api will be read out of
shell-api/VERSION.txt -
The
build_releasetarget ensures that a link to theshell-apiof the matching version installed below/usr/binwill be set up when the debian package of the generated app is installed. This is achieved via thedebian/linkfile.
For this reason, it is recommended to use installation via Debian packages, since the dependencies will be managed consistently across different versions of shell api.
Configuration
By default, a configuration file is at the app’s disposal as described in the shell-api documentation. Here, for the sample 'TestApp' app generated in Example, the configuration file is:
.config/TestApp/testapp.yml
The accepted format is a very restricted subset version of YAML. Only basic pairs key: value are accepted. Please check the shell-api documentation.
|
Example
$ ./shell-api/genapp TestApp -y --author="Michel Mehl" --email="michel.mehl@slashetc.fr" --desc="A test application" --github-id="michelm33" --root-release-dir="../release"
info generated testapp/VERSION.txt
info generated testapp/CHANGELOG.txt
info generated testapp/EXAMPLES.txt
info generated testapp/LICENSE.txt
info generated testapp/COPYRIGHT.txt
info generated testapp/Makefile
info generated testapp/pack/
info generated testapp/testapp.yml
info generated testapp/testapp
info generated testapp/testapp__vars.sh
info generated testapp/testapp__options.sh
info generated testapp/testapp__help.sh
Genapp has finished.
$ testapp/testapp
info Creating user's configuration file '/home/michel/.config/TestApp/testapp.yml' from '/home/michel/Data/Data/admin/linux/testapp/testapp.yml'
Hello!
$ testapp/testapp -h
Usage: testapp OPTIONS [<sample usage arg>]
or: testapp OPTIONS [<sample usage arg 2>]
OPTIONS:
--silent Silent mode
--verbose Verbose mode
--debug Activate debug logs
--help, -h Displays app usage
-y Assume 'Yes' when prompted for confirmation
-n Assume 'No' when prompted for confirmation
-v, --version Displays the app version
--man Displays the manual page
--files Lists all the files used by the app (config, log etc)
Arguments:
<sample arg> put your argument short description here. Copy/paste in new line and change for additional ones.
$ ./testapp/testapp --files
/home/michel/.config/TestApp/testapp.yml
/home/michel/.local/testapp/log.txt
/home/michel/.local/testapp/dependencies.yml
$ cd testapp
$ make release
# ..
# MAKE OUTPUT INTENTIONALY REMOVED FOR THE SAKE OF READABILITY
# ..
$ ls ../release/testapp/
testapp-1.0-0 testapp_1.0-0.zip testapp_1.0-0_amd64.buildinfo testapp_1.0-0_amd64.deb
testapp-1.0_0.orig.tar.xz testapp_1.0-0_amd64.build testapp_1.0-0_amd64.changes
$ cd testapp
$ make man
help2man is installed
help2man -L en_EN@euro --no-info --section 8 --name "Test suit for sumo" --help-option="--man" --output=testapp.8 ./testapp
Installing man pages and building gzip for /usr/share/man/man8//testapp.8
sudo install -g 0 -o 0 -m 0644 testapp.8 /usr/share/man/man8/
sudo gzip -f /usr/share/man/man8//testapp.8
$ man testapp
TESTAPP(8) System Administration Utilities TESTAPP(8)
NAME
TestApp - A test application
SYNOPSIS
testapp OPTIONS [<sample usage arg>]
testapp OPTIONS [<sample usage arg 2>]
Arguments:
# REMAINING STANDARD OUTPUT TRACES INTENTIONALLY REMOVED FOR THE SAKE OF READABILITY
# ...
$ cat testapp/COPYRIGHT.txt
TestApp
Copyright (c) 2026 Test User. All rights reserved.
License terms written down in file LICENSE.txt
API for each module
See API page
Lifecycle
Configuration management
The configuration management of the original software was originally managed on a non-disclosed server with arcv. The original revision log of arcv can be tracked on this page: Full revision log page.
Since version 1.1.2, the full original source code is available on GitHub under LGPL license. Therefore, it will be used as the main source reference for the public version.
The clean release packages and the release source code files are available on GitHub at https://github.com/michelm33/shell-api
Bug tracking
Reported bugs are tracked via the GitHub page https://github.com/michelm33/shell-api
Tests
There’s a bunch of unit tests available in the 'self-test' module. However, many of them were one-shot runs commented out afterwards.
In the long run, the tests should ideally be organized in an automated test hardness, which is run prior to any release.
The API is deemed to be somehow instrinsically tested through the various tools using it extensively for their running, and indireclty via their own automated tests.
External platforms
LGPL License
The library is under LGPL-3 license.
Supporting this work
You can contribute by enriching yourself the library. You can also support the original author via its donation page Donate & Gifts online page.
Thanks
-
The Linux community
-
The stack overflow community which is a precious source of support and information that may save your day sometimes!
-
help2man an utility to generate man pages
-
'meld' tool
-
Google Translate
Probably this list may be completed over time, sorry if I missed anyone!