【问题标题】:"for i" without "in [sequence]" ending while using getopt使用 getopt 时没有“in [sequence]”结尾的“for i”
【发布时间】:2013-04-19 10:03:11
【问题描述】:

我找到了这个在 shell 中使用 getopt 命令的示例脚本。

#!/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

效果很好,但我不明白变量 $i 分配在哪里。它如何知道它必须遍历 $arg。你能解释一下吗?

【问题讨论】:

  • bash 手册页可以,在for 循环的描述下。

标签: bash shell getopt


【解决方案1】:

here 所示,如果没有给出in seqfor 默认为$@for i 分配您的 $i 变量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-27
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    • 2023-01-08
    • 2015-08-05
    • 2011-01-07
    • 1970-01-01
    相关资源
    最近更新 更多