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

落花浮王杯 提交于 2019-12-21 13:01:26

问题


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:


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



来源:https://stackoverflow.com/questions/16102089/for-i-without-in-sequence-ending-while-using-getopt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!