0

I am trying to run a program which should run within a time range. I have written the bash script snippet below, from what I have read about bash if-elif-else-fi constructs, to select the time range. I have no idea why it does not work. Help will be appreciated.

#!/bin/bash
year=`date "+%Y"`
month=`date "+%m"`
day=`date "+%d"`
hour=`date "+%H"`

 print $year, $month, $day, $hour
   if [ $hour >= 00 && $hour < 03 ]
    then
         hr = "00"
   elif [ $hour >= 03 && $hour < 06 ]
    then
         hr = "03"
   elif [ $hour >= 06 && $hour < 09 ]
    then
         hr = "06"
   elif [ $hour >= 09 && $hour < 12 ]
    then
         hr = "09"
   elif [ $hour >= 12 && $hour < 15 ]
    then
         hr = "12"
   elif [ $hour >= 15 && $hour < 18 ]
    then
         hr = "15"
   elif [ $hour >= 18 && $hour < 21 ]
    then
         hr = "18"
   else
         hr = "21"
   fi
   print $hr

Here is what I get

Error: no such file "2020,"
Error: no such file "04,"
Error: no such file "08,"
Error: no such file "22"

./ogmet_data.sh: line 10: [: missing `]'
./ogmet_data.sh: line 13: [: missing `]'
./ogmet_data.sh: line 16: [: missing `]'
./ogmet_data.sh: line 19: [: missing `]'
./ogmet_data.sh: line 22: [: missing `]'
./ogmet_data.sh: line 25: [: missing `]'
./ogmet_data.sh: line 28: [: missing `]'
./ogmet_data.sh: line 32: hr: command not found
Zilore Mumba
  • 1,346
  • 4
  • 23
  • 33

0 Answers0