Logic error shell script

0

I want to print a message on the screen according to the current time of day but it always falls on the other, what would be the error? I've been to 1h and I do not understand the error.

    
asked by anonymous 07.07.2018 / 00:08

2 answers

2

The following comparison is unnecessary and will never be true:

elif [ "$HORA" -ge 12 -a "$HORA" -lt 06 ]
then
    echo "Boa Noite!";
else

See the solution:

#!/bin/bash

HORA=$(date +%H)

if [ "$HORA" -ge 6 -a "$HORA" -lt 12 ]
then
     echo "Bom dia!";
elif [ "$HORA" -ge 12 -a "$HORA" -lt 18 ]
then
    echo "Boa tarde!";
else
    echo "Boa noite!";
fi
    
07.07.2018 / 02:38
1

Try this, but I'm not so sure.

 #!/bin/bash

 clear
 HORA=$(date +%H)

 if [ "$HORA" -gt 05 -a "$HORA" -lt 12 ]
 then
     echo "Bom dia";

 elif [ "$HORA" -gt 11 -a "$HORA" -lt 18 ]
 then
     echo "Bom tarde";

 elif [ "$HORA" -gt 17 -o "$HORA" -lt 6 ]
 then
     echo "Bom noite";
 fi

I think the problem is in the hour, if you are running at night, there is no way the time is greater than 18 and less than 6

    
07.07.2018 / 02:18