lundi 27 août 2018

shell script missing semicolon in if statement and no syntax error?

Someone pointed out a missing semicolon in a simple shell script and I'm curious why it's not throwing a syntax error.

Full script:

interval () {
    INTERVAL="$*"
    WHEN_TO_RUN=0
    while read LINE; do
        if (( $(epoch 0S) >= $WHEN_TO_RUN )) then
            echo $LINE
            WHEN_TO_RUN="$(epoch $INTERVAL)"
        fi
    done
}

line in question:

if (( $(epoch 0S) >= $WHEN_TO_RUN )) then

I'm also confused as to why the parens make that line work, when I'd normally expect:

if [ $(epoch 0S) -ge $WHEN_TO_RUN ]; then

on OSX if relevant

Aucun commentaire:

Enregistrer un commentaire