Tyilo
Tyilo

Reputation: 30122

Comparing strings in if and using or

This code is not working, but I don't know what's wrong. If I only use single brackets the string isn't compared right.

#!/bin/bash
forceupdate=false
currentVersion=520-19
latestVersion=520-19
if [[ "$latestVersion" > "$currentVersion" -o forceupdate ]]
then
    echo -e "\nupdate!\n"
else
    echo -e "\nno update!\n"
fi

Upvotes: 0

Views: 106

Answers (1)

glenn jackman
glenn jackman

Reputation: 247012

$forceupdate inside brackets will actually be true, because it's not going to execute the false executable, but it will see a non-empty string.

if [[ "$latestVersion" > "$currentVersion" ]] || $forceupdate

Upvotes: 2

Related Questions