2016-10-29 77 views
0

我的问题是,下面的代码抛出这样的错误猛砸如果elif和else从句

./sync.sh: Line 25: Syntaxerror at `then [translated to english] 

我的代码不会因为它应该工作在我的Linux脚本是:

#!/bin/bash 

[...] 

if [["$input1" == 1 && "$input2" == 1]] 
    then 
     #local herunterladen 
     echo "Es wird nun local herunterladen" 
    elif[["$input1" == 1 && "$input2" == 2]] 
    then 
     #local hochladen 
     echo "Es wird nun local hochgeladen" 
    elif [["$input1" == 2 && "$input2" == 1]] 
    then 
     #online herunterladen 
     echo "Es wird nun online herunterladen" 
    elif[["$input2" == 2 && "$input2" == 2]] 
    then 
     #online hochladen 
     echo "Es wird nun online hochgeladen" 
    else 
     echo "${red}Du hast einmal nicht ${green}1${red} oder ${green}2${red} gedrückt!${reset}" 
fi 

我的系统是用Linux作为shell的Arch Linux,但我认为这并不重要。

+1

运行它[shellcheck](http://www.shellcheck.net/) –

回答

1

您需要[[]]附近的空格。

如果您阅读Bash手册,您会发现[[]]保留字。与元字符(如())不同,如果它们紧挨着其他普通字符,则不会被检测到。