lundi 20 février 2017

Bash script IF and || creates syntax error

I have a bash script where I wish to write into a file if one of the commands inside an IF statement ends with nonzero (so when it exits with an error). However with the following I get a syntax error with an unexpected "else" at the end. Am I using this error writing right?

if [[ $f != */.* ]]; then
        echo "$f"
        command-one || { echo 'Something went wrong with Command-one at file ' $f ' !' >> ../corrupted.txt } || error=1
        command-two || { echo 'Something went wrong with Command-two at file ' $f ' !' >> ../corrupted.txt } || error=1
        command-three || { echo 'Something went wrong with Command-three at file ' $f ' !' >> ../corrupted.txt } || error=1
        if [ error == 0 ]
        then
            echo "====================================================" >> ../ok.txt
            echo "All went well with: " $f >> ../ok.txt
        fi
        error=0
    else
        echo "This file is corrupted: " $f >> ../corrupted.txt
    fi

Aucun commentaire:

Enregistrer un commentaire