Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我知道“for循环”可以用来遍历所有参数。但是对于我的代码,我更喜欢
i = 1 if [ ${$i} == xx] ; then xxx fi ((iArg++)) if [ ${$i} == xx] ; then xxx fi
显然,${$i} 不起作用。我该如何使它正确?
我曾经使用写 csh
$argv[$i]
现在必须使用 sh shell。感谢帮助
由于这个非常困难,参数解析通常使用$1and来完成shift。一个典型的循环可能如下所示:
$1
shift
while [ $# -gt 0 ]; do case $1 in -a) echo "-a"; shift 1;; # option with no argument -b) echo "-b $2"; shift 2;; # option which takes argument, use $2 -c) echo "-c"; shift 1;; esac done
也就是说,间接变量名的方法是 with !,如:
!
${!i}