A Bash library of assertions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
Franco Masotti 150343ac7e Description fix. 3 years ago
LICENSE First commit. 3 years ago
README.md Description fix. 3 years ago
fbla Added license notice. 3 years ago
test_fbla Added license notice. 3 years ago

README.md

fbla

A Bash library of assertions

Table of contents

Functions

Function name Description Notes
assert_isinstance checks if a variable correponds to a data type every input evaluates to a string. Python 3 data type names are used for type identification

Key

  • every element between < and > is to be considered pseudocode.
  • list of values are presented in this format: 'value a','value b','value n'

Function descriptions

  • assert_isinstance

    prototype:
        assert_isinstance(value,type)
    input:
        value = <any value including an empty string>
        type  = 'bool','int','str'
    output:
        return 0 <if true>
        return 1 <if false>
    

Version

0.0.1

See all fbla releases.

Usage

You can adapt and include the library as a separate part of your program by using source ./fbla or . ./fbla from the main script.

To allow inclusion in any project the template and its documentation is released under the CC0 1.0 license.

Bashisms

Bashisms are Bash specific syntax elements. I decided to use these because of programming convenience rather than compliancy.

You will find at least the following bashisms in the library

Bashism Example
local variables local variable='value'
conditional expression [[ "${variable}" = 'hello' ]]
regual expresion binary operator [[ "${variable}" =~ [0-9] ]]
pattern matching [[ "${variable}" =~ [:alnum:] ]]

GNU Bash "strict mode"

This template enables the shell's "strict mode". You can disable it by commenting or removing the following line inside fbopt:

set -euo pipefail

Conventions

The following elements should be common sense and not be specific to fbopt

Convention Notes Examples
all constants are enclosed within single quotes elements within single quotes (only) are not interpreted by the shell 'constant' or 'this is a constant'
some variables are enclosed within double quotes double quotes serve as a delimiter between multiple variable names if these are consecutive. Every variable between the quotes is interpolated "${variable}"
some variables are not enclosed within double quotes the only variables allowed without double quotes are integers (such as return values) and loop iterators (because these won't work otherwise) ${?} or for v in ${values}; do echo "${v}"; done
all variables use the curly braces notation curly braces serve as a delimiter between multiple variable names if these are consecutive "${variable}" or ${variable}
all variable names with a constant value must be capital case you might want to load some constants from a configuration file to override the values of options within the fbopt file local flag_a="${FLAG_A_DEFAULT_VALUE}"

Dependencies

The template is known to work with the the packages listed here. These must be of course installed on your system.

Package Executable Version command Package Version
GNU Bash /bin/bash $ bash --version GNU bash, version 4.4.23(1)-release (x86_64-unknown-linux-gnu)

Tests

You can run tests like this:

$ ./test_fbla

These also serve as usage example.

Software using fbla

License

Written in 2019 by Franco Masotti/frnmst franco.masotti@live.com

To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.

You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see http://creativecommons.org/publicdomain/zero/1.0/.