"for i" without "in [sequence]" ends when using getopt

I found an example script to use the getopt command in the shell.

#!/bin/bash args=$(getopt ab $*) set -- $args for i; do case "$i" in -a)shift; echo "it was a";; -b)shift; echo "it was b";; esac; done 

It works well, but I don't understand where the $ i variable is assigned. How does he know that he should iterate through $ arg. Can you explain this?

+6
source share
1 answer

As shown here , for by default $@ if not specified in seq . for i assigns your variable $i .

+11
source

All Articles