In a linux bash script, I want to have two lists of arguments: one are those started with single dash and the other those started with double dash. For example:
script -a 1 --b=3 -c 7 --d=8
Then it can return them in two group variables:
group1 : -a 1 -c 7
group2 : --b=3 --d=8
I know that $@ holds a list of all arguments. I don't know whether I should iterate them and make them distinct or there are easier solutions. This is my try:
g1=""
g2=""
for i in $@; do
echo $i
if [[ $i == --* ]]; then
g1="${g1} $i"
else
g2="${g2} $i"
fi
done
echo $g1
echo $g2
regardless of its accuracy, it says:
test.sh: 5: [[: not found