#! /bin/bash
count=1
step=(a b)
for x in 0 1
do
if [[ $count != '0' ]]; then
if [[ ${step[x]} = "a"]]; then
echo "Python test ($count)"
else
echo "stress test"
fi
fi
done
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
syntax error in conditional expression: unexpected token `;'
line 20: syntax error near `;
line 20: ` if [[ ${step[x]} = "a"]]; then'
Run Code Online (Sandbox Code Playgroud)
为什么?
你需要在第二个"a"和]]第二个之间留一个空格if.
技术上更多,[[并且]]必须是单独的标记,而bash的解析器不会在引号或大多数标点符号上分隔标记.
我相信这行的原始代码相当于if [[ ${step[x]} = "a]]"; then如果这使得问题更加明显.