[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Handling long-options with getopts
From: |
fatiparty |
Subject: |
Handling long-options with getopts |
Date: |
Sat, 30 Oct 2021 06:53:07 +0000 |
I am parsing options with `getopts` but would like to handle long-options as
well.
mygetopts ()
{
aggr=()
for arg in "$@"; do
case $arg in
("--context") aggr+=( "-C" ) ;;
(*) aggr+=( "$arg" ) ;;
esac
done
set -- "${aggr[@]}"
local OPTIND OPTARG
local shortopts="C:"
while getopts "$shortopts" arg; do
case $arg in
("C") context="$OPTARG" ;;
(*) break ;;
esac
done
}
But I wonder whether the use of `set -- "${aggr[@]}"` is correct.
Or is the following (using `eval`) more appropriate?
eval set -- "${aggr[@]}"
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Handling long-options with getopts,
fatiparty <=