{"id":13815670,"url":"https://github.com/agriffis/pure-getopt","last_synced_at":"2025-04-05T22:32:34.122Z","repository":{"id":7535289,"uuid":"8887208","full_name":"agriffis/pure-getopt","owner":"agriffis","description":"drop-in replacement for GNU getopt implemented in pure Bash","archived":false,"fork":false,"pushed_at":"2021-02-01T17:05:21.000Z","size":85,"stargazers_count":63,"open_issues_count":0,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-21T13:22:45.383Z","etag":null,"topics":["bash","getopt"],"latest_commit_sha":null,"homepage":null,"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/agriffis.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":"2013-03-19T19:27:09.000Z","updated_at":"2025-02-06T02:06:34.000Z","dependencies_parsed_at":"2022-08-27T18:21:11.149Z","dependency_job_id":null,"html_url":"https://github.com/agriffis/pure-getopt","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agriffis%2Fpure-getopt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agriffis%2Fpure-getopt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agriffis%2Fpure-getopt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agriffis%2Fpure-getopt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/agriffis","download_url":"https://codeload.github.com/agriffis/pure-getopt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247411250,"owners_count":20934650,"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","getopt"],"created_at":"2024-08-04T04:03:51.202Z","updated_at":"2025-04-05T22:32:33.881Z","avatar_url":"https://github.com/agriffis.png","language":"Shell","funding_links":[],"categories":["Shell"],"sub_categories":[],"readme":"# pure-getopt\n\n[![Build Status](https://travis-ci.com/agriffis/pure-getopt.svg?branch=master)](https://travis-ci.com/github/agriffis/pure-getopt)\n\npure-getopt is a drop-in replacement for GNU getopt, implemented in pure\nBash compatible back to 2.05b. It makes no external calls and faithfully\nreimplements GNU getopt features, including:\n\n * all three calling forms in the synopsis\n * all getopt options\n * matching error messages\n * matching return codes\n * proper handling of abbreviated long options\n * alternative parsing mode (long options with single dash)\n * GETOPT_COMPATIBLE flag\n * POSIXLY_CORRECT flag\n * leading + or - on options string\n\n# How to use it\n\npure-getopt provides a single bash function `getopt` that you can insert\ndirectly into your script. It should be defined before calling `getopt` from\nyour code, so either place the definition above your code, or use this\npattern (recommended):\n\n```bash\n#!/bin/bash\n\nmain() {\n    declare argv\n    argv=$(getopt -o fb: --long foo,bar: -- \"$@\") || return\n    eval \"set -- $argv\"\n\n    declare foo=false bar=\n\n    while true; do\n        case $1 in\n            f|foo) foo=true ; shift ;;\n            b|bar) bar=$2 ; shift 2 ;;\n            --) break ;;\n        esac\n    done\n\n    # etc\n}\n\n# INSERT getopt function here\ngetopt() {\n    ...\n}\n\n# CALL main at very bottom, passing script args.\n# The test here distinguishes script execution from \"source myscript.bash\" which\n# will define the functions without calling main, for calling functions from\n# another script or testing at the command-line.\n[[ $BASH_SOURCE != \"$0\" ]] || main \"$@\"\n```\n\n# Differences between pure-getopt and GNU getopt\n\nThe only intentional divergences between pure-getopt and GNU getopt are\neither inconsequential or due to bugs in GNU getopt:\n\n 1. GNU getopt mishandles ambiguities in abbreviated long options, for\n    example this doesn't produce an error message:\n\n        getopt -o '' --long xy,xz -- --x\n\n    but this does produce an error message:\n\n        getopt -o '' --long xy,xz: -- --x\n\n    Pure-getopt generates an error message in both cases, diverging from\n    GNU getopt to fix this bug.\n\n 2. In the case of an ambiguous long option with an argument, GNU getopt\n    generates an error message that includes the argument:\n\n        getopt: option '--x=foo' is ambiguous; possibilities: '--xy' '--xz'\n\n    We consider this a bug in GNU getopt, since the value might be very\n    long and inappropriate for printing to the screen, and since GNU getopt\n    ordinarily omits the value in its error messages. Pure-getopt's error\n    message in this case is:\n\n        getopt: option '--x' is ambiguous; possibilities: '--xy' '--xz'\n\n 3. Pure-getopt uses a different method of quoting the output. The result\n    is the same as GNU getopt when eval'd by the shell.\n\n# References\n\n * [getopt in util-linux](http://software.frodo.looijaard.name/getopt/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagriffis%2Fpure-getopt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagriffis%2Fpure-getopt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagriffis%2Fpure-getopt/lists"}