mercredi 4 novembre 2020

"If" statement with "and" operator - daytimes

I have issues with the last if in this example:

#!/bin/bash

sunrise="05:00:00";
currenttime=$(date -u +%H:%M:%S);
sunset="18:00:00"


if [[ "$sunrise" < "$currenttime" ]] ; then
    echo works1;
fi

if [[ "$sunset" > "$currenttime" ]] ; then
    echo works2;
fi

# during the day:
if [[ "$sunrise" < "$currenttime" ]] && [[ "$currenttime" > "$sunset" ]] ; then
    echo works3;
fi

I get the output of the first two echo but not from the last one.

What am I doing wrong?

Of course I'm doing this tests now at 11:30.

Aucun commentaire:

Enregistrer un commentaire