{"id":18898268,"url":"https://github.com/powerpuffpenguin/bash-snippets","last_synced_at":"2026-04-27T11:31:13.455Z","repository":{"id":156873456,"uuid":"626280013","full_name":"powerpuffpenguin/bash-snippets","owner":"powerpuffpenguin","description":"bash code snippets","archived":false,"fork":false,"pushed_at":"2023-05-10T15:21:45.000Z","size":155,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-31T19:25:18.980Z","etag":null,"topics":["args-parser","bash","bash-script","command-line","library","shell-script"],"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/powerpuffpenguin.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":"2023-04-11T06:39:31.000Z","updated_at":"2023-04-28T03:31:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"c41810ed-c585-4f4b-a281-dc3b55ba3a75","html_url":"https://github.com/powerpuffpenguin/bash-snippets","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/powerpuffpenguin/bash-snippets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powerpuffpenguin%2Fbash-snippets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powerpuffpenguin%2Fbash-snippets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powerpuffpenguin%2Fbash-snippets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powerpuffpenguin%2Fbash-snippets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/powerpuffpenguin","download_url":"https://codeload.github.com/powerpuffpenguin/bash-snippets/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powerpuffpenguin%2Fbash-snippets/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32335295,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"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":["args-parser","bash","bash-script","command-line","library","shell-script"],"created_at":"2024-11-08T08:41:44.447Z","updated_at":"2026-04-27T11:31:13.437Z","avatar_url":"https://github.com/powerpuffpenguin.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"[中文](README.zh.md)\n\n# bash-snippets\n\nHere's some reusable bash code and tools I've written with the primary goal of\nsimplicity and ease of use.\n\nIf not specified otherwise, download the individual files and they will work\nwithout any additional dependencies.\n\n```\nsource dst/strings.sh\n\nif strings_end_with \"$s\" \"$end\";then\n    echo \"yes, '$s' end with '$end'\"\nfi\n```\n\n- [layout](#layout)\n- [result](#result)\n- [declaration](#declaration)\n- [test.sh](#test)\n- [api](document/en/README.md)\n\n# layout\n\n- **dst** This folder contains all reusable code repositories\n- **example** This folder contains some usage examples\n- **src** Some code generated from source in src\n- **generate.sh** Executing this script regenerates the archive created by the\n  code\n- **test.sh** A bash unit testing tool\n\n# result\n\nThe bash function cannot return anything other than an integer. The solution is\nto use a global variable to return, or use echo return string. This library uses\nglobal variables to return content for functions (echo cannot return an array,\nand it is difficult to return the error reason when the function fails).\n\n1. If an error occurs in the function, the description string of the error will\n   be set to the variable `result_errno=...`, after which the function returns\n   an error code `return errno`\n2. If the function has a return value, set the return content to the variable\n   `result=...`\n\n```\n# return value\nif ! get_value; then\n  echo \"errno: $?\"\n  exit 1\nfi\necho \"value=$result\"\n\n\n# return array\nif ! get_array; then\n  echo \"errno: $?\"\n  exit 1\nfi\ni=0\nfor val in \"${result[@]}\";do\n    echo \"value[$i] = $val\"\n    i=$((i+1))\ndone\n```\n\n# declaration\n\nA good function declaration tells humans how it should be used and what it will\nreturn. I provides functions declarations like 'typescript' format.\nUnderstanding how to understand the declaration is the most concise and fast way\nto master the use of functions, Here are some examples:\n\n```\nfunction strings_split(s: string, separators: string): []string\n```\n\n\u003e The strings_split function accepts two positional parameters, a string 's' and\n\u003e 'separators', and the function returns a string array after separating 's'.\n\n```\n(separator: string, ...s: []string): string\n```\n\n\u003e The above declaration omits the function name, which is usually written above\n\u003e the function in the source code, because the name already exists in the source\n\u003e code. In addition... s means variable length parameter.\n\n```\n(): errno\n```\n\n\u003e The errno return value indicates that this function is a discriminant, usually\n\u003e only for use with if, it has no return content\n\n```\n() (id: number, errno)\n```\n\n\u003e The above function returns a number to the result variable, and because of the\n\u003e existence of errno, this function may have an error `return errno`\n\n```\n(): panic\n() (id: number, panic)\n```\n\n\u003e panic means that when the function fails, bash will be automatically terminated, and the call stack and available error messages will be printed\n\n\n# test\n\nOnly tested code should be used with confidence, especially bash Scripts are\noften used for system administration and can cause system crashes directly if\nnot tested.\n\ntest.sh is a unit test tool I wrote for bash, it found in the source code\nstarting with test_ prefix the function and execute, at the same time, some\ntest-related information can be printed. There are many files suffixed with\n_test.sh under the dst folder, you can refer to them to write unit test code,\n[dst/assert.sh](document/en/assert.md) some functions are provided to simplify\nthe test code.\n\nView instructions for use:\n\n```\n./test.sh -h\n```\n\nTest specified file:\n\n```\n./test.sh dst/strings_test.sh dst/path_test.sh\n```\n\nTest all files (*_test.sh) under the specified folder:\n\n```\n./test.sh\n./test.sh -d dst\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowerpuffpenguin%2Fbash-snippets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpowerpuffpenguin%2Fbash-snippets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowerpuffpenguin%2Fbash-snippets/lists"}