“for i” without “in [sequence]” ending while using

2019-04-08 03:14发布

I've found example script for using getopt command in 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 work well, but I don't understand where is variable $i assigned. How it knows that it must iterate through $arg. Can you explain this?

1条回答
混吃等死
2楼-- · 2019-04-08 03:34

As shown here, for defaults to $@ if no in seq is given. The for i assigns your $i variable.

查看更多
登录 后发表回答