0

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.

1
  • 1
    Run it through shellcheck Commented Oct 29, 2016 at 17:46

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

It is if you want to use && inside the conditional expression. [[ ... ]] is different (and in many ways superior to) [...].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.