0

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
4
  • Well, yeah. [ is a different command. Commented May 24, 2011 at 15:41
  • But how do i make the -o work? Commented May 24, 2011 at 15:43
  • The -o is fine. That's not the problem. Commented May 24, 2011 at 15:45
  • Could you please tell me what's wrong then instead of me having to guess it? Commented May 24, 2011 at 16:01

1 Answer 1

2

$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
Sign up to request clarification or add additional context in comments.

1 Comment

@David, I meant $forceupdate. The code in the question has a variable by that name, and I assumed the -o expression contained a bug.

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.