shell 脚本返回空输出

shell script returning null output

我无法调试它返回

null
值的原因。有人可以帮忙吗。

代码-

getJSONParamater() {
       echo "Before :   "
       eval "=$(cat  | jq '.""')"
       echo "After :   "
}

return_value='default'
getJSONParamater etl-without-transformation.json  success_email return_value

echo $return_value

jq '.""' 将发送文字 ."" 作为 jq 的表达式,你想要的是:

jq --arg key "" '.[$key]' ""

还删除了无用的 cat

我不太明白你想用 eval 部分做什么?但我猜你正试图将 return_value 设置为 jq?

的结果
getJSONParameter() {
  jq --arg key "" '.[$key]' ""
}

return_value="$(getJSONParameter "etl-without-transformation.json" "success_email")"

另一种使用全局变量的方法:

return_value='default'
getJSONParamater() {
       return_value=$(cat "" | jq "")
}
getJSONParamater etl-without-transformation.json  .success_email
echo $return_value