getoptsy
getoptsy: getopts alternative to parse command line arguments to long options, in POSIX, using custom code.
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (11.7%) to scientific vocabulary
Repository
getoptsy: getopts alternative to parse command line arguments to long options, in POSIX, using custom code.
Statistics
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
getoptsy: getopts alternative to parse long options in POSIX
This "getoptsy" Unix shell script is demonstration of how to parse command line arguments to long options, by using while...case, all in POSIX code.
The source code and detailed comments show how to process these options:
Long options, such as
--helpfor help,--verbosefor verbose, etc.Short options, such as
-hfor help,-vfor verbose, etc.Short options as runs, such as "-vvv" for verbose level 3.
Value options such as
--foo=bar,--foo bar,-f bar, etc.
About this demonstration
This demonstration aims to show how you can write your own code.
This demonstration does not aim to provide a drop-in replacement for
getopts, or its specification, or its way of describing options, etc.;
if you want that, then we can suggest getopts_long, linked below.
We welcome constructive feedback and ideas for improvements.
Usage
Syntax:
sh
getoptsy [options] [arguments]
Options:
txt
-h|--help Print this help
-v|--verbose Increment the verbose level (multiple use)
--foo bar|--foo=bar Set foo to bar
-- Finish options parsing
Examples:
```sh getoptsy --help
=> Print this help
getoptsy -vvv
=> Increment the verbose three times
getoptsy --foo bar
=> Set foo to bar
```
Comparisons
Comparisons to other command line arguments options parsing:
POSIX getopts supports short options and runs, but not long options.
POSIX-compatibe getops_long supports everything her, but is complex.
Bash shell getopt supports both options, but not other shells.
Why use POSIX?
This script aims to work with the POSIX standard, because this tends improves portability and compatibility with a wide range of systems.
The POSIX standard provides a tool to get options, named getopts.
This supports for one-character "short options", such as -h for help,
and does not support multi-character "long options", such as --help.
We know that some developers strongly favor runs of short options,
such as -abc which is intended to be equivalent to -a -b -c.
We believe that long options tend to help people learn and use scripts.
For example some of our daily tools now offer an option --dry-run,
and some of our administration tools now offer an option --danger
to help caution the user to take more care about the command usage.
We believe the best approach will use POSIX compatibilty, short options, runs of short options, and long options. So we created the code below.
Why use a shell script?
If you're reading this, then you probably already know there are many alternatives for writing commands, such as by using higher-structure languages, which provide better argument parsing, more capabilties, etc.
If you're writing a shell script, then it's wise to know the limitations. For example, you may want to consider changing to a different language if your shell script has above a hundred or so lines of code, or has many options, or uses complex logic, or involves work of high value to you.
For the future
We advocate for the POSIX standard group members to consider a future POSIX release that upgrades the getopts tool by adding support for long options.
A new getops with long options will supersede the "getoptsy" script. It will help many shell scripts, and many users, and many developers, by providing a standard built-in way to parse arguments into options.
Tracking
- Package: unix-shell-script-posix-args-opts-like-getops
- Version: 1.0.1
- Created: 2022-10-23T10:25:48Z
- Updated: 2022-10-25T18:54:19Z
- License: GPL-2.0-or-later or contact us for custom
- Website: https://github.com/sixarm/unix-shell-script-posix-args-opts-like-getops
- Contact: Joel Parker Henderson (joel@joelparkerhenderson.com)
Owner
- Name: SixArm
- Login: SixArm
- Kind: organization
- Email: sixarm@sixarm.com
- Location: San Francisco
- Website: http://sixarm.com
- Twitter: sixarm
- Repositories: 580
- Profile: https://github.com/SixArm
SixArm Software
Citation (CITATION.cff)
cff-version: 1.2.0
title: getoptsy: getopts alternative to parse long options in POSIX
message: >-
If you use this work and you want to cite it,
then you can use the metadata from this file.
type: software
authors:
- given-names: Joel Parker
family-names: Henderson
email: joel@joelparkerhenderson.com
affiliation: joelparkerhenderson.com
orcid: 'https://orcid.org/0009-0000-4681-282X'
identifiers:
- type: url
value: 'https://github.com/SixArm/getoptsy/'
description: getoptsy: getopts alternative to parse long options in POSIX
repository-code: 'https://github.com/SixArm/getoptsy/'
abstract: >-
getoptsy: getopts alternative to parse long options in POSIX
license: See license file
GitHub Events
Total
- Watch event: 1
- Push event: 1
- Fork event: 1
Last Year
- Watch event: 1
- Push event: 1
- Fork event: 1
Committers
Last synced: 12 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Joel Parker Henderson | j****l@j****m | 11 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 12 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0