#!/bin/bash
X=storing system name
if [ $X = "ABC" ];
echo " $X "
then
elif [ $X = "DEF" ] || [ $X = "GHI" ] || [ $X = "JKL" ]
echo " $X "
else
echo " $X "
fi
这不起作用。
./elif.sh: line 8: syntax error near unexpected token `elif'
./elif.sh: line 8: `elif.....
任何人,请帮忙。 版本Linux 3.0.101-107
问候
答案 0 :(得分:1)
then
。
同样如@Dharck Duffy指出
$X
不加引号意味着有几种不受欢迎的影响 - 考虑X='1 = 1 -o BCF'
- 然后[ $X = "ABC" ]
变为[ 1 = 1 -o BCF = ABC ]
,即使OP打算使用的字符串也会返回true比较完全不相同。如果它是[ "$X" = ABC ]
,则不会发生这种情况。
#!/bin/bash
X=storing system name
if [ "$X" = "ABC" ];then
echo " $X "
elif [ "$X" = "DEF" ] || [ "$X" = "GHI" ] || [ "$X" = "JKL" ];then
echo " $X "
else
echo " $X "
fi
答案 1 :(得分:1)
你的shell脚本中有很多错误。首先是为了评估您需要在引号中添加内容所需的变量。而当时的用法并不正确。
bash if condition
的语法#!/bin/bash
X="storing system name"
if [ "$X" = "ABC" ]; then
echo " $X "
elif [ "$X" = "DEF" ] || [ "$X" = "GHI" ] || [ "$X" = "JKL" ]; then
echo " $X "
else
echo " $X "
fi
我修改了你的脚本。
* def getstorewalk = {"walkzz":"001","zz":zz,"ddd":"zz","zz":{"zz":"zz","who":{"zz":"11","zz":"zz"}},"departments":[{"id":need to extract this id,"name":"zz","someorder":1,"zzs":[{"zz":zz,"name":"zz (zz, zz, zz, zz & zz)","someorder":zz,"zz":[{"zz":51,"name":"zz Spread","someorder":16,"zz":"Available","zz":[{"zz":"1223","zz":"zz 30g","zz":3,"zz":0,"zz":"stale","zz":false,"zz":true,"zz":[],"zz":{"zz":2,"zz":"zz","zz":6,"zzName":"Core zz (zz)","department":56,"zz":"015 zz Spreads","zz":"zz Spread","subzz":100,"somezz":"zz & zz","zz":{},"zz_":100},"zz":{"zz":"2017-09-21T11:09:15.524Z","who":{"zz":"11","zz":"zz"}},"action":{"zz":"Include"},"zz":[{"capturezz":375716,"zz":"Gap","qty":15,"zz":"zz","zz":{"zz":"zz","type":"N","name":"zz","sequence":1},"zz":{"zz":"211","who":{"zz":"11","zz":"zz"}}}]}]}]}]}]}
* def departmentId = getstorewalk.departments[*].id
* print departmentId