How to check for passed options using getopts in a POSIX shell? (Report, count, and discard.)
-1
votes
1
answer
557
views
How to check for passed options using
getopts
(man page) in a POSIX shell? (Report, count, and discard.)
My idea is this: Many of my scripts take no options (not even -h
for help, I am transitioning to help
directly. And so, if any number of options (switches) is given, I want to count them, report them, and simply discard them (Don't do any action on them).
Let's include all 0-9
, and both lower and upper a-z
(A-Z
).
---
**Update:** Many of my scripts do not take even files as arguments, and that is the case with this script.
---
**Usage** help looks like this:
usage ()
{
cat << EOF
MPV video player subtitles enable/disable toggling
--------------------------------------------------
on Enable subtitles toggling in MPV.
off Disable subtitles toggling in MPV.
help Print this help message.
version Print the script version.
EOF
}
Asked by Vlastimil Burián
(30515 rep)
Jun 20, 2023, 03:13 AM
Last activity: Jun 20, 2023, 12:45 PM
Last activity: Jun 20, 2023, 12:45 PM