![bash:意外标记“elif”附近的语法错误](https://linux22.com/image/92774/bash%EF%BC%9A%E6%84%8F%E5%A4%96%E6%A0%87%E8%AE%B0%E2%80%9Celif%E2%80%9D%E9%99%84%E8%BF%91%E7%9A%84%E8%AF%AD%E6%B3%95%E9%94%99%E8%AF%AF.png)
shell脚本片段如下
if [[ $OS == Linux ]] ; then
LINUX_FC=gfortran
#
# set 32 or 64 Bits executable
#
ARCH=`uname -m`
echo "PROCESSOR IS: $ARCH"
if [ [ $ARCH == x86_64 ] ] ; then
BITS=SIXTYFOUR;
else
BITS=THIRTYTWO;
fi
elif [[ $OS == Darwin ]] ; then
DARWIN_FC=gfortran;
else
BITS=THIRTYTWO;
fi;
错误是
OPERATING SYSTEM IS: Linux
: command not found
jobcomp1: line 34: syntax error near unexpected token `elif'
'obcomp1: line 34: `elif [ [ $OS == Darwin ] ] ; then
答案1
shell 确实不喜欢括号之间的空格:
if [ [ $ARCH == x86_64 ] ] ; then
它期望类似的东西
if [[ $ARCH == x86_64 ]] ; then
或更好)
if [ $ARCH = x86_64 ] ; then
(制作特定于 bash 的脚本是没有意义的,因此也==
变得=
如此)。