语法错误Cygwin如果否则条件
问题描述:
我使用Cygwin来运行脚本,当我使用if else条件时出现语法错误。 你能告诉我我的脚本有什么问题吗?语法错误Cygwin如果否则条件
./test.sh:第10行:附近意外的标记
else' ./test.sh: line 10:
别的语法错误'
#!/bin/bash
date
schema=''
table='JJJJ'
first=${table:0:1}
echo $first
if [$first == 'J']
echo 'SUCCESS';
else
echo 'error';
fi
感谢
答
你if
说法是不正确:
if [ "$first" == 'J' ]; then
echo 'SUCCESS';
else
echo 'error';
fi
注意then
声明,为$first
可变双引号。
+0
谢谢:)它的工作原理 –
答
像这样的东西用shellcheck.net。您的if
附近有语法错误。
正确的代码 -
#!/bin/bash
date
schema=''
table='JJJJ'
first=${table:0:1}
echo $first
if [ $first == 'J' ]
then
echo 'SUCCESS';
else
echo 'error';
fi
你错过了'then'。 '['和'$ first'之间的空格。我可以建议使用http://www.shellcheck.net吗? – Biffen