David Parks
David Parks

Reputation: 32081

Bash if statement: Can I do an assignment and comparison?

I want to do something like:

if [ CURRENT=$(stat -c %Y $STATUS_FILE) -ne $LASTUPDATE ]
    then LASTUPDATE = $CURRENT
fi

That is... I want to assign a variable and do a comparison since I'll use that variable later

Upvotes: 8

Views: 3549

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799150

Absolutely.

$ echo "$foo"

$ echo "${foo=$(echo bar)}"
bar
$ echo "$foo"
bar

Upvotes: 10

Related Questions