SPJS01Pro
SPJS01Pro

Reputation: 79

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.

Upvotes: 0

Views: 249

Answers (2)

webcitron
webcitron

Reputation: 142

Check for Bash conditions syntax (ex http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-6.html). Bash need spaces before and After [ and ]. Moreover - doubleing of [ and ] is unnecesarry

Upvotes: 0

tom
tom

Reputation: 22939

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.

Upvotes: 1

Related Questions