【问题标题】:Check exit status of function with itself exit status使用自身退出状态检查函数的退出状态
【发布时间】:2015-08-14 14:02:44
【问题描述】:

我在1.sh 中有一个函数ff,退出状态为33。 当我在2.sh 中调用此函数并调用函数ff 时,如果退出状态为33,那么我的2.sh 已损坏。 我怎样才能做一个继续步骤? 像这样:

if [ exit_of_ff -ne 0 ]
then
 continue
fi

【问题讨论】:

  • 我不明白你的具体问题。请更准确,并努力使用结构良好的句子来表达您的问题。
  • 你想“继续”更具体的是什么
  • @BertrandMartel 我猜他不想让他的 2.sh 坏掉,而是抓住出口继续工作
  • BertrandMartel - 你是对的。

标签: bash exit-code


【解决方案1】:

不是真正的答案,而是格式化的评论。

如果你有

ff() {
    if [ some_condition ]; then
        return 33
    fi
    return
}

然后,通常要检查错误情况,您会这样做

if ! ff; then
    echo function ff returned non-zero
    exit
fi
echo function ff returned success

如果要存储退货状态

ff
status=$?
if [[ $status -eq 33 ]]; then ...

【讨论】:

    【解决方案2】:

    我这样解决了这个问题:

    如果(ff $参数) 然后 ff $参数 菲

    在 ff 中,我有 3 个在 ( ) 之后无法访问的参数

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-27
      • 2023-03-05
      • 1970-01-01
      相关资源
      最近更新 更多