{"id":21461517,"url":"https://github.com/zix99/bash-minimist","last_synced_at":"2025-07-06T03:41:54.288Z","repository":{"id":38200646,"uuid":"208920752","full_name":"zix99/bash-minimist","owner":"zix99","description":"NodeJS Minimist inspired shell script for parsing arguments","archived":false,"fork":false,"pushed_at":"2023-11-19T18:47:25.000Z","size":13,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-11-19T19:35:59.223Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zix99.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-17T00:06:58.000Z","updated_at":"2023-09-08T09:55:10.000Z","dependencies_parsed_at":"2022-08-19T10:01:21.556Z","dependency_job_id":null,"html_url":"https://github.com/zix99/bash-minimist","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zix99%2Fbash-minimist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zix99%2Fbash-minimist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zix99%2Fbash-minimist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zix99%2Fbash-minimist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zix99","download_url":"https://codeload.github.com/zix99/bash-minimist/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226012294,"owners_count":17559651,"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":[],"created_at":"2024-11-23T07:09:30.229Z","updated_at":"2024-11-23T07:09:30.819Z","avatar_url":"https://github.com/zix99.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bash-minimist\n\n[![Build Status](https://travis-ci.org/zix99/bash-minimist.svg?branch=master)](https://travis-ci.org/zix99/bash-minimist)\n\n*bash-minimist* is a lightweight bash script inspired by the NodeJS module [minimist](https://github.com/minimistjs/minimist).\n\nIt is meant to be a very simple and non-invasive argument parser.  It will convert any flags or positional arguments into appropriate variables and expose them to your script.\n\nThis will fit into your application well 90% of the time for simple things, and once you outgrow it, it should be easy to convert.\n\n## Usage\n\nDownload [minimist.sh](minimist.sh) and place in your script path.\n\nAdd `source minimist.sh` to your script after your shebang.\n\nSee [minimist.example.sh](minimist.example.sh) for a complete example, and the header of *minimist.sh* for details.\n\n```sh\n#!/bin/bash\nsource minimist.sh\n\n# Now my variables are exposed via ARG_\n# Positional args have been rewritten, and all flags are excluded. So $1, $2, $3, etc will only be positional\nif [[ $ARG_HELP == 'y' ]]; then\n\techo \"Someone passed --help\"\nfi\n```\n\n## Configuration\n\nAt the top of *minimist.sh* there are a few configurable items, which you can change inline or set before calling minimist.\n\nFor instance, to export any parsed args (rather than just setting locally-scoped variables), you could do:\n\n```sh\n#!/bin/bash\nAOPT_DECLARE_FLAGS=\"-rx\" # Readonly, export on 'declare'\nsource minimist.sh\n\necho \"Now other scripts can access $ARG_\"\necho \"A: $ARG_A\"\n\n# Single-character flags are case-sensitive\necho \"Flag: $ARG_f $ARG_d $ARG_D\"\n\necho \"Pos1: $1\"\n```\n\nNow, you can call the script like the following:\n```sh\n$ minimist.sh --a=123 mypositional\n# OR\n$ minimist.sh mypositional --a=123\n# OR\n$ minimist.sh mypositional --a=456 -fD\n```\n\n## Error checking\n\nThe script by itself provides minimal input sanitation.  Any non-alphanumeric character will be replaced by a `_`\n\nIf there is still an error after sanitation, an error will be thrown by default (configurable).\n\nAll other validation is expected to be done by the script (required variables, valid values, etc).\n\n### Error on Unknown Arguments\n\nThe script can exit if an argument is unknown, eg.\n```bash\nAOPT_VALID_ARGS=(\"verbose\" \"v\") # Define acceptable arguments\nsource minimist.sh\n```\n\n`./myscript --unknown` would throw an error and exit, while `--verbose` or `-v` would be accepted.\n\n# License\n\nThe MIT License (MIT)\nCopyright (c) 2019 Chris LaPointe\n\nPermission 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:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE 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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzix99%2Fbash-minimist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzix99%2Fbash-minimist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzix99%2Fbash-minimist/lists"}