{"id":16153886,"url":"https://github.com/hinto-janai/stdlib","last_synced_at":"2026-05-08T00:35:31.317Z","repository":{"id":45820564,"uuid":"514610657","full_name":"hinto-janai/stdlib","owner":"hinto-janai","description":"a standard library for Bash","archived":false,"fork":false,"pushed_at":"2022-08-28T18:17:20.000Z","size":268,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-13T05:42:17.604Z","etag":null,"topics":["bash","library","linux","shell"],"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/hinto-janai.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}},"created_at":"2022-07-16T15:09:27.000Z","updated_at":"2022-08-03T18:59:08.000Z","dependencies_parsed_at":"2022-09-05T21:31:38.966Z","dependency_job_id":null,"html_url":"https://github.com/hinto-janai/stdlib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hinto-janai%2Fstdlib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hinto-janai%2Fstdlib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hinto-janai%2Fstdlib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hinto-janai%2Fstdlib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hinto-janai","download_url":"https://codeload.github.com/hinto-janai/stdlib/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247569130,"owners_count":20959758,"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","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","library","linux","shell"],"created_at":"2024-10-10T01:14:49.848Z","updated_at":"2026-05-08T00:35:26.295Z","avatar_url":"https://github.com/hinto-janai.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# stdlib\n\u003ea standard library for Bash\n\n![bash](https://user-images.githubusercontent.com/101352116/179367439-68a06efc-56bf-4899-82d9-1fe8d21b11fc.svg)\n\n## Contents\n- [About](#About)\n- [Development](#Development)\n- [Usage](#Usage)\n- [trace()](#trace)\n- [List](#List)\n\n## About\nThis is a library of boilerplate functions meant for general-purpose Bash programming. Requires at least Bash v4.4+ (2016), but Bash v5+ is recommended (2018). For reference, current **old-old Debian** (Stretch 9) uses Bash v4.4-5, while current stable Debian (Bullseye 11) uses Bash v5.1.4.\n\nAll functions have usage and more fine-grain documentation within the file it belongs to.\n\n## Development\nThe all-in-one `stdlib.sh` file containing all library functions is created using [hbc, a Bash compiler.](https://github.com/hinto-janaiyo/hbc) hbc itself relies on portions of this library as well, leading to a symbiotic relationship between the two. You don't need to use hbc to use this library, however.\n\n## Usage\nFunction groups are seperated by files, you can directly source them, copy+paste the functions directly into your own scripts [or preferably, use hbc to \"compile\" this library together with your script.](https://github.com/hinto-janaiyo/hbc) If you'd like to use the entire library, the entire set of functions has already been built as `stdlib.sh`.\n\nFirst, clone:\n```bash\ngit clone https://github.com/hinto-janaiyo/stdlib\n```\n\nSourcing a single function set:\n```bash\nsource stdlib/src/crypto.sh\n```\n\nSourcing everything:\n```bash\nsource stdlib/stdlib.sh\n\nhash::md5 \"hello\"\nlog::ok   \"all functions\"\narray     \"are[0]=sourced\"\n```\n\nUsing [hbc](https://github.com/hinto-janaiyo/hbc):\n```bash\n#include \u003cstdlib/log.sh\u003e\n\nlog::ok \"click above to see more info on hbc\"\n```\n\n## trace()\nThis is a very special function in the stdlib, most likely the most useful and most important.\n\n`trace()` is the very much needed Bash error-handler. It's written 100% with Bash builtins (no external binaries). It catches any command that has errored in-between the function pair, traces everything, prints detailed information (including an inline view of your code), then exits, terminating any sub-shells.\n\nWhile every stdlib file only needs itself to operate correctly, some stdlib functions contain a small variable export ($STD_TRACE_RETURN) that lets `trace()` print just a little bit more information on stdlib-related errors. If you do not use `trace()`, the variable export will be harmless and do nothing instead.\n\nEXAMPLE CODE:\n```\n___BEGIN___ERROR___TRACE___      \u003c-- this function initiates trace()\n\necho \"good command\"              \u003c-- these commands will run fine\necho \"this is fine\"\n\nVAR=$(null_command)              \u003c-- this null_command will FAIL and trigger\n                                     trace + debug + exit. without trace(), $VAR\n                                     would now be NULL or \"\", making the next\n                                     command catastrophic.\n\nrm -rf $VAR/*                    \u003c-- this dangerous rm won't execute because\n                                     trace() exit on the last command. without it,\n                                     this would remove your /* root directory.\n\n___ENDOF___ERROR___TRACE___      \u003c-- this closes, and disables trace()\n```\nEXAMPLE OUTPUT:\n![trace](https://user-images.githubusercontent.com/101352116/179367505-7f781c94-ca0c-4fa9-8f94-33fde38e113e.png)\n\n## List\nBrief summaries on each library file.\n\n### [ask()](https://github.com/hinto-janaiyo/stdlib/blob/main/src/ask.sh)\n```\nPrompt for user input.\n````\n### [color()](https://github.com/hinto-janaiyo/stdlib/blob/main/src/color.sh)\n```\nPermanently set terminal text color, 100x-200x~ faster than tput.\n```\n### [crypto()](https://github.com/hinto-janaiyo/stdlib/blob/main/src/crypto.sh)\n```\nGenerate crypto.\n```\n### [date()](https://github.com/hinto-janaiyo/stdlib/blob/main/src/date.sh)\n```\nFormat the date in useful ways. Includes UNIX time and a translator.\n```\n### [debug()](https://github.com/hinto-janaiyo/stdlib/blob/main/src/debug.sh)\n```\nA better set -x. Traces and prints every command in the style of trace().\n```\n### [guard()](https://github.com/hinto-janaiyo/stdlib/blob/main/src/guard.sh)\n```\nSelf-calculate the hash of the script running, return error on modified hash.\nUseful for preventing tampering of a script.\n```\n### [hash()](https://github.com/hinto-janaiyo/stdlib/blob/main/src/hash.sh)\n```\nHash stdin or input with:\nMD5 - SHA1 - SHA256 - SHA512\n```\n### [is()](https://github.com/hinto-janaiyo/stdlib/blob/main/src/is.sh)\n```\nCheck if input is an integer, postive, negative, etc.\n```\n### [lock()](https://github.com/hinto-janaiyo/stdlib/blob/main/src/lock.sh)\n```\nCreate and manage a lock file to prevent multiple script/function instances.\n```\n### [log()](https://github.com/hinto-janaiyo/stdlib/blob/main/src/log.sh)\n```\nPrint formatted messages to the terminal.\n```\n### [panic()](https://github.com/hinto-janaiyo/stdlib/blob/main/src/panic.sh)\n```\nPrint error information and enter endless loop to prevent further code execution.\n```\n### [$readonly](https://github.com/hinto-janaiyo/stdlib/blob/main/src/readonly.sh)\n```\nCommon global variables set as readonly, includes COLOR variables:\n$RED - $BRED - $BGREEN, etc\n```\n### [safety()](https://github.com/hinto-janaiyo/stdlib/blob/main/src/safety.sh)\n```\nSafety functions to disarm potentially dangerous shell operations.\n```\n### [trace()](https://github.com/hinto-janaiyo/stdlib/blob/main/src/trace.sh)\n```\nDetailed error handler for Bash, using 100% builtins.\n\nFunction pair much like try \u0026 catch. Catches any error between it, traces it,\nprints detailed debug info, and exits.\n```\n### [type(), free()](https://github.com/hinto-janaiyo/stdlib/blob/main/src/type.sh) \u0026 [const()](https://github.com/hinto-janaiyo/stdlib/blob/main/src/const.sh)\n```\nSafely initialize GLOBAL variables with certain types. Will return error if\nthe variable is already found to exist.\n\nfree() unsets variables.\n\nconst() converts already initialized variables into constants (readonly).\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhinto-janai%2Fstdlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhinto-janai%2Fstdlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhinto-janai%2Fstdlib/lists"}