vendredi 28 octobre 2016

Command not found unix shell scripting

So I'm currently working on a school project and I'm trying to write a shell script that will eventually decide which class gradle will build on. But I keep getting an error each time I choose either 1 or 2, but if I select anything else, the script prompts me the correct results.

Example 1: If input = 1

Do you wish to play Tic Tac Toe as a web app or simply in the terminal? (1)Web app (2)Terminal
1
./testScript.sh: line 6: [ 1: command not found
1

Example 2: If input != 1 or 2

Do you wish to play Tic Tac Toe as a web app or simply in the terminal? (1)Web app (2)Terminal
5
You have insulted us, go home!

-

#!/bin/sh

echo "Do you wish to play Tic Tac Toe as a web app or simply in the terminal? (1)Web app (2)Terminal"
read input

if [ "$input" != "1" ] || [ "$input" != "2" ]; then
    echo "You have insulted us, go home!"
elif [ "$input" = "1" ]; then
    echo "1"
elif [ "$input" = "2" ]; then
    echo "2"
fi

I've read and googled but the only suggestion I find is that I need to add spaces between if and [, and between [ and ". But as you can see that is not the case.

Aucun commentaire:

Enregistrer un commentaire