SPJS01Pro SPJS01Pro - 1 month ago 12
Linux Question

Bash if elif and else doesn't work as it should in my linux script

My Problem is, the following code throws errors like

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


My Code is:

#!/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


My System is Arch Linux with Fish as shell, but I think this deosn't matter.

tom tom
Answer

You need spaces around [[ and ]].

If you read the Bash manual, you'll find that [[ and ]] are reserved words. Unlike metacharacters such as ( and ), they are not detected if they are right next to other ordinary characters.