{"id":23908569,"url":"https://github.com/mandober/bing-bash","last_synced_at":"2026-05-18T00:06:35.690Z","repository":{"id":156251898,"uuid":"54062217","full_name":"mandober/bing-bash","owner":"mandober","description":"Bash functions library","archived":false,"fork":false,"pushed_at":"2016-05-21T05:32:19.000Z","size":172,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-06T07:11:20.657Z","etag":null,"topics":["bash"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mandober.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-16T19:55:31.000Z","updated_at":"2024-07-29T12:45:07.000Z","dependencies_parsed_at":"2023-05-21T18:30:12.421Z","dependency_job_id":null,"html_url":"https://github.com/mandober/bing-bash","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mandober/bing-bash","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mandober%2Fbing-bash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mandober%2Fbing-bash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mandober%2Fbing-bash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mandober%2Fbing-bash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mandober","download_url":"https://codeload.github.com/mandober/bing-bash/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mandober%2Fbing-bash/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267342212,"owners_count":24071881,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash"],"created_at":"2025-01-05T04:38:55.296Z","updated_at":"2026-05-18T00:06:30.651Z","avatar_url":"https://github.com/mandober.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bing-bash  \n  \n## ![bingbash](https://img.shields.io/badge/bing-bash-orange.svg?style=flat-square) Bash functions library\n  \n\n* [About](#about)\n* [Quick start](#quick-start)\n* [Description](#description)\n* [Usage](#usage)\n* [Conventions](#conventions)\n  - [Naming conventions](#naming-conventions)\n  - [Positional parameters](#positional-parameters)\n  - [Short options](#short-options)\n  - [Long options](#long-options)\n  - [Operands](#operands)\n* [List of functions](#list-of-functions)\n* [Features](#features)\n  \n  \n### About  \nLibrary of bash functions comprising routines for dealing with variables, arrays, strings, functions, symbols table, etc.  \n  \n  \n### Quick Start\nJust download and source the functions you need.   \nApart from few, all functions are standalone, they don't depend on any other function or file from this library. Those that are, have their dependencies specified in the corresponding help section.  \n  \n  \n### Description\nThe library is composed using bash's (4.3) features, without unnecessary forking (when possible) or usage of external tools (unless faster). Single process bash shell was in high regard as well as bash's specific functionalities. Made and tested with bash 4.3 (and 4.4-beta).  \n  \n  \n### Usage\nFunctions are meant to be sourced, though some of them could be executed as well. All functions are standalone and they don't need any other function or file from this library (unless explicitly stated), but as a convenience, there are some function management capabilities available (see `bing-bash`, `load` and `bb` files).\n  \n* Files containing functions can be sourced individually and then functions can be called as usual. This way functions will, of course, stay resident, but at least all the environment-polluting code will make the functions instantly responsive.\n* One level down in comparison to the above is to have functions marked for autoloading; although not a true autoloading, as in other shells. Namely, when marked for autoloading, a stand-in, eponymous function will be created, only a few lines long (as opposed to the whole function's body) whose purpose is to source its complete definition when first called.\n* The last and most environment friendly way is to call functions through `bb` function dispatcher that will load called function, pass arguments to it and unload it when done. This way is also convenient during fiddling with function's body, as it always sources the current function's code.  \n  \n  \n### Conventions\n  \n#### Naming Conventions\nNames of all functions are prefixed with `bb_` as an attempt to pseudo-namespace them so they won't collide with other eponymous tools, scripts and functions. On the other hand, files that define these functions are named without such prefix, with a `.bash` extension added. This makes it easy to separate files that contain functions from other files; the exceptions to this is `load` file that has no extension (because it contains autoloading function code).  \n  \nIf you're sure no naming collisions exist on your system, you can, of course, make aliases (e.g. `alias typeof=bb_typeof`) to shorten function's names; some aliases are already defined in `bing_aliases` file.  \n  \n\u003e\nNames of variables local to functions all have `bb` prefix followed by capital letter (e.g. `bbParam`), so avoid passing similarly named parameters to minimize problems.\n  \nNames of environment variables used are all upper-cased and have `BING_` prefix (e.g. `BING_FUNC`).\n  \n#### Positional Parameters\nPositional parameters are divided into options and operands (non-option parameters).  \nOptions are further divided into:  \n* flags (options without arguments)  \n* options that have required argument  \n* options that have an optional argument  \n  \nOptions are also divided into short (`-o`) and long options (`--long-option`).  \n  \nOperands can be explicitly separated from options by using double dash `--`; for example, `function -options -- PARAM1 PARAM2` in which case everything after '--' is treated as an operand, even if it starts with '-' or '--'. Otherwise (i.e. without '--'), **order** of options and operands is not important (unless specifically noted for a particular function).  \n* If the same option is repeated, the latter will overshadow the former occurrence.\n* If unrecognized option is supplied, it will be discarded.  \n  \n#### Short Options\nA short option begins with a dash (-) followed by a single character.\n* If the option has **no argument** it is called a simple option or a flag e.g. `-x`.  \n* If the option has **required** argument it may be written:  \n  - *immediately* after the option character, e.g. `-rREQ`  \n  - as the *following* parameter, e.g. `-r REQ`  \n* If the option has **optional** argument, it must be written *immediately* after the option character, e.g. `-rOPT`  \n   \nIt is possible to specify several short options after one '-' (compounded short options), as long as all (except possibly the last) options are flags: `-xyz`, `-xyzr req`  \n  \n#### Long Options\nA long option normally begins with double dash (--) followed by the long option name (which is a string of alphanumerics and dash).  \n* If the long option has **no argument** it is called a simple option or a flag e.g. `--long-option`  \n* If the option has *required* argument, it may be written:\n  - as the *following* argument, e.g. `--option REQ`\n  - after the *equal sign*, e.g. `--option=REQ`\n* If the option has **optional** argument, it must be written after the *equal sign*, e.g. `--option=OPT`  \n   \nLong options may be **abbreviated**, as long as the abbreviation is \n  *unambiguous*, e.g. `--long` instead of `--long-option`.\n    \n\u003e \nNOTE: Important thing to note about this library is that all functions will parse canonically provided parameters (i.e. no compounded short options, no abbreviations of long options) internally, in the body of function itself, which means faster execution. Otherwise `getopt` utility will be called to parse parameters, which may sometimes result in slower function's execution.  \n  \n#### Operands\nAn operand to a function can be passed by name or by value.  \n* Array variables are always passed by name (without $).  \n* Scalar variables can be passed by name (without $) or by value (with $, as usual).  \n  \nAs a convenience, instead of passing a variable by value, possibly with quotations (e.g. `function \"$var\"`) you can just type `function var` to pass it by name.  \n\u003e\nNaturally, a value can also be passed directly (`function \"abcd\"`), in which case there may be unexpected results if it happens that a variable by that name (a variable called `abcd`) already exist.  \n  \nSince arrays cannot be passed around in bash (nor exported), they are always passed by name (without $). Trying to pass an array with `$array` will only pass its zeroth element (if any) and passing an array as `${array[@]}` could work at the cost of having its indices/keys discarded; still not very practical, especially when two or more arrays need to be passed to a function.  \n\n#### Common options\nThese 3 options are guaranteed to be accepted in all functions:  \n`--help` show help  \n`--usage` show usage  \n`--version` show version  \nShort-option equivalents of above options, `-h`, `-u` and `-v` (including their capital case form) are frequent, but are not to be relied upon as they might have been used for something else entirely.  \n  \n`-v, --verbose`\nMost functions also accept setting of verbosity level via `-v, --verbose LEVEL` option, where optional option-argument LEVEL is: 0 for quiet - no error output, 1 for output of fatal error messages (default level), 2 for extensive informational output, 3 for debugging output; verbosity levels can also be set the traditional way as `-v, -vv, -vvv`, which correspond to levels 1, 2 and 3 respectively.\n   \n`-o, --out`\nIf a function accepts user supplied name for a variable that will hold function's resulting value, this is always achieved via `-o, --out NAME` option, followed by required option-argument NAME that must be valid identifier. If the option-argument is a number 1-9 (inclusive) the output will be sent to this file descriptor.   \n   \n  \n### List of functions  \n(at the moment, some functions encompass functionalities that perphaps shouldn't've been merged together in a single functions as subroutines)  \n  \n* `bb_typeof`   \nPretty dump arrays and their attributes is its main purpose.  \nType and qualify given string: identify it as set or unset variable, array, shell keyword, etc. With `-t` option, only the type, as a single word is returned: unset, variable, indexed, associative; also those returned by type builin: alias, keyword, function, builtin or file.  \n(feat: [d][] [h][] [o][] [m][] [p][] [s][] [t][])  \n  \n* `bb_explode`  \nConvert a string to array by splitting it by substring which can be a single or multi-character substring; convert a string to array of individual characters. Needs \"predict a delimiter\" feature.   \n  \n* `bb_implode`  \nConvert an array to string. Specify wrapping, prefix, suffix and *glue* characters.  \n  \n* `bb_array_clone`  \nClone an array.  \n\n* `bb_array_merge`  \nMerge two or more arrays of any type (indexed and/or associative). User can force the type of resulting array and specify merging mode (reindex, skip, overwrite, append).  \n  \n* `bb_array_convert`  \nConvert indexed to associative array or associative to index array, discarding the keys.  \n  \n* `bb_array_remove`  \nRemove one or more element by specifying index/key. Remove many elements by specifying comma-separated list of strings (associative) or ranges (mainly for indexed arrays). \n  \n* `bb_array_shift`  \nReturn the value of the first element by removing it and shifting remaining elements down.  \n  \n* `bb_array_sort`  \nSort array different ways. Remove duplicated values from an array.  \n\n* `in_array`  \nChecks if a value, scalar or array, exists in an array.  \n    \n* `bb_range`  \nGenerate numeric sequences from list of ranges and individual integers (e.g. 1,4-8,10,15-20,25-30). Specify numbers base and divider, prefix, suffix characters.  \n  \n* `bb_venn`  \nScalars, strings, arrays and Venn diagrams: union, intersection, difference, complement.  \n  \n* `bb_load`  \nLoad and unload functions. Mark functions for autoloading. Resolve functions path.  \n   \n* `bb_pad`  \nPad a string by appending char(s) after each character of the string. \n  \n* `bb_trim`  \nTrim leading, trailing and intermediate whitespace.  \n  \n* `bb_to`  \nConversions between hex, octal, decimal, ascii.  \n  \n* `bb_sql`  \nRoutines dealing with sqlite database.  \n  \n* `bb_is`  \nPattern matching subroutines: qualify string as alphabetic, alpha-numeric, etc.; qualify name as valid identifier, filename, path; qualify variables as set, null, indexed, associative, etc.    \n  \n* `bb_get`  \nCollect information about variables, their attributes, arrays, variable's length and type, etc.  \n  \n* `bb_array`  \nArray quick dump.  \nIdentify array as associative and indexed.  \nIdentify indexed array as numeric, packed, sparse.  \nReturn array's keys, values, empty elements, max, min values.  \nSqueeze an array.  \nPack an array.  \n   \n  \n### Features  \nOr tasks. Check-list of features that are, or need to be, implemented.  \n`c` completions  \n`d` documentation, rationale and steps included in comments   \n`h` up to date --help  \n`o` output result to given var or FD  \n`m` man page completed  \n`n` pass scalars (also) by name (in applicable functions)   \n`p` positionals (parse canonical params before involving `getopt`)  \n`s` standalone function (no deps on any other function)  \n`t` tests provided  \n`u` unified names for options across functions  \n`v` Verbosity levels or TMI  \n`-` possibility provided to get params from stdin  \n    \n  \n[c]: #features  \"completions\"\n[d]: #features  \"documentation\"\n[h]: #features  \"help\"\n[o]: #features  \"output\"\n[m]: #features  \"man\"\n[n]: #features  \"pass-by-name\"\n[p]: #features  \"positionals\"\n[s]: #features  \"standalone\"\n[t]: #features  \"tests\"\n[u]: #features  \"unified\"\n[v]: #features  \"verbosity\"\n  \n  \n### Definitions\n(used in comments, help sections, man pages)   \n**identifier**  a word consisting solely of underscores, digits and alphabetic characters from the POSIX portable character set. First char must not be a digit.  \n`[[:alpha:]_][[:alnum:]_]+`  \n**portable character set**  POSIX portable character set consists of 8 chars from Control Character Set: NULL, BELL, BACKSPACE, TAB, CARRIAGE RETURN, LINE FEED, VERTICAL TAB, FORM FEED and X characters from ASCII range 32-126.  \n**FQPN**  Fully qualified path name.  \n**name**  a word consisting solely of underscores, digits and alphabetics.  \n**char**  Any character.  \n**string**  Sequence of characters.  \n**substring**  Sequence of characters that are part of the string.  \n**filename**  POSIX portable filename, hyphen not 1st char.  \n`[[:alnum:]._][[:alnum:].-_]+`  \n**pathname**  POSIX portable filename, hyphen not 1st char.  \n`[[:alnum:]._/][[:alnum:].-_/]+`   \n**alias**  POSIX portable name of alias.  \n`[[:alnum:].-_/!%,@]`  \n**var**  Name of scalar or array variable.  \n**scalar**  Name of scalar variable.  \n**array**  Name of array variable.  \n**assoc**  Array whose keys are strings.    \n**indexed**  Array whose indexes are numeric.  \n**packed array**  Indexed array with contiguous indexes that start from 0.  \n**sparse array**  Indexed array with non-contiguous indexes.  \n**whitespace**  Space, tab, vertical tab, new line.  \n**flag**  Option with 2 states: present/absent.  \n**argument**  Argument to an option.  \n**required**  Required argument.  \n**optional**  Optional argument.  \n  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmandober%2Fbing-bash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmandober%2Fbing-bash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmandober%2Fbing-bash/lists"}