blip.bash - Bash Library for Indolent Programmers
#!/bin/bash
set -euo pipefail
source /usr/lib/blip.bash
main () {
local name="$(get_gecos_name)"
if get_user_confirmation "Is your name ${name:-(unknown)}?" ; then
echo "Nice to meet you ${name:-mystery user}."
else
echo "I'll just call you $(get_username) then."
fi
}
main "$@"blip is a Bash Library for Indolent (lazy) Programmers. It is a bash script that is intended to be sourced in as a library of common functions to aid development of shell scripts.
This project is still in the early stages of development and is expected to change. However, with the mantra release early, release often, in mind, it is available in this early state to help solicit feedback and user input.
Please feel free to contact the author or offer patches to the source.
Alias for abs ().
See also: select bash built-in.
See also: select bash built-in.
Alias for is_abs_int ().
Return 0 (true) if $ARG1 may be considered boolean false by a human.
Values to be considered true include: 0, false, no, off, disable and
disabled.
Return 0 (true) if $ARG1 is a floating-point value.
Return 0 (true) if $ARG1 is an integer value.
Alias for is_int ().
Return 0 (true) if $ARG1 may be considered boolean true by a human.
Values to be considered true include: 1, true, yes, on, enable and
enabled.
Return 0 (true) if $URL exists, as determined by a 2XX HTTP response
code. Otherwise returns 1 (false).
Requires the curl command to be present in the shell search path.
Outputs (echos to STDOUT) the full HTTP response headers returned by the
remote web server for $URL.
Requires the curl command to be present in the shell search path.
Outputs (echos to STDOUT) the HTTP response code (including textual
description) returned by the remote web server for $URL. Follows HTTP
redirects using curl's -L flag, returning only the last HTTP response code.
Requires the curl command to be present in the shell search path.
Similar to url_http_response, except the textual description is omitted,
outputting only the numerical value.
See COMMAND LINE ARGUMENT PARSING.
See COMMAND LINE ARGUMENT PARSING.
See COMMAND LINE ARGUMENT PARSING.
See COMMAND LINE ARGUMENT PARSING.
See COMMAND LINE ARGUMENT PARSING.
See COMMAND LINE ARGUMENT PARSING.
Used internally by command line argument parsing (cmdarg_parse() function),
not usually expected to be used directly. See COMMAND LINE ARGUMENT PARSING.
Used internally by command line argument parsing (cmdarg_describe()
function), not usually expected to be used directly. See
COMMAND LINE ARGUMENT PARSING.
Used internally by command line argument parsing (cmdarg_parse() function),
not usually expected to be used directly. See COMMAND LINE ARGUMENT PARSING.
Used internally by command line argument parsing (cmdarg_set_opt() function),
not usually expected to be used directly. See COMMAND LINE ARGUMENT PARSING.
Documentation relating to command line argument parsing can be found in the
blip.bash(7) man page. It can also be viewed online in the
CMDARG.md file at
https://github.com/neechbear/blip/blob/master/CMDARG.md.
Contains the version of blip as a string value.
Example: 0.01-3-prerelease
A 4-element array containing version information about the version of blip.
Example:
BLIP_VERSINFO[0] = 0 # Major version number
BLIP_VERSINFO[1] = 01 # Minor version number
BLIP_VERSINFO[2] = 3 # Patch / release number
BLIP_VERSINFO[3] = prerelease # Release statusThese variables contain common ANSI terminal colour codes.
A list of all keys within the ANSI associative array may be obtained through
the following code example:
BLIP_ANSI_VARIABLES=1
source /usr/lib/blip.bash
echo "${!ANSI[@]}"See also BLIP_ANSI_VARIABLES in the ENVIRONMENT section below.
See COMMAND LINE ARGUMENT PARSING.
See COMMAND LINE ARGUMENT PARSING.
See COMMAND LINE ARGUMENT PARSING.
The following variables are used internally by the command line argument
parsing: CMDARG, CMDARG_REV, CMDARG_OPTIONAL, CMDARG_REQUIRED,
CMDARG_DESC, CMDARG_DEFAULT, CMDARG_VALIDATORS, CMDARG_INFO,
CMDARG_FLAGS, CMDARG_TYPES.
These variables are not intended to be read or modified directly.
See COMMAND LINE ARGUMENT PARSING.
When set to 1, inhibits exit functionality to abort operation
when blip determines that it is not running inside a bash shell interpreter.
See also BLIP_INTERNAL_FATAL_ACTION.
Specifies the command to execute when blip encounters a fatal internal
condition such as being called by an incompatible foreign shell, or not meeting
the minimum version requirements set by the BLIP_REQUIRE_VERSION variable.
Defaults to exit 2.
See also: BLIP_REQUIRE_VERSION.
Specifies the minimum version of blip required by the calling parent script.
blip will exit with a non-zero (2) return code if the
${BLIP_VERSINFO[@]} array does not indicate a version that is equal to
or greater.
Example:
BLIP_REQUIRE_VERSION="0.02-13"
source /usr/lib/blip.bashWhen set to 1, causes blip to declare read-only variables containing
common ANSI terminal colour codes. All declared variable names being with
the prefix ANSI_, with the excption of one associative array which is
simply ANSI.
A list of all declared ANSI variables may be obtained through the following code example:
BLIP_ANSI_VARIABLES=1
source /usr/lib/blip.bash
compgen -A variable | grep ANSISee also: https://en.wikipedia.org/wiki/ANSI_escape_code.
Specifies an explicit command path when executing the external dependency
command flock. Defaults to flock without an explicit path in order to
search $PATH.
Specifies an explicit command path when executing the external dependency
command stat. Defaults to stat without an explicit path in order to
search $PATH.
Specifies an explicit command path when executing the external dependency
command bc. Defaults to bc without an explicit path in order to
search $PATH.
Specifies an explicit command path when executing the external dependency
command curl. Defaults to curl without an explicit path in order to
search $PATH.
Specifies an explicit command path when executing the external dependency
command date. Defaults to date without an explicit path in order to
search $PATH.
Specifies an explicit command path when executing the external dependency
command grep. Defaults to grep without an explicit path in order to
search $PATH.
Nicola Worthington ([email protected]).
https://nicolaw.uk/blip, https://github.com/neechbear/blip/.
/usr/share/doc/blip, bash(1), blip.bash(7).
Copyright (c) 2016,2017 Nicola Worthington ([email protected]). With contributions from Sergej Alikov, 2016.
Command line argument parsing functionality is adapted from the cmdarg.sh
library (ttps://github.com/akesterson/cmdarg),
which is written by and Copyright (c) 2013 Andrew Kesterson ([email protected]).
This software is released under the MIT License.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.