我对jq很陌生,很难获得json值并在bash语句中使用它。
{
"animal": "elephant",
"colour": "red"
}VAR=$( jq '.animal' animal.json )
echo "$VAR"
if [[ "$VAR" == "elephant" ]]; then
echo "this is an elephant"
else
echo "failed"
fi当我运行脚本时,比较失败
什么可以改变使脚本工作?
发布于 2022-09-08 14:55:15
jq输出"elephant",注意"
将-r添加到jq命令中,以便删除引号(原始模式)
然后输出将与字符串elephant匹配。
#!/bin/bash
VAR="$(jq -r '.animal' animal.json)"
echo "$VAR"
if [[ "$VAR" == "elephant" ]]; then
echo "this is an elephant"
else
echo "failed"
fihttps://stackoverflow.com/questions/73651039
复制相似问题