-1

This question already has an answer here:

Actually i want to create an array of dates and compare it to the today date if it match with the current date then execute test.sh file otherwise exit the loop in bash script. I did like this...

**#!/bin/bash**

cd /home/user1

current_date=$(date +%Y-%m-%d)

array=['2016-03-02','2016-03-010','2016-05-10']

for i in "${array[@]}" do

    if [ $now -eq $i ]; then

        echo "executing your bash script file"

        ./myscript.sh

    fi

done

when i execute above script then it gives error like ./sample.sh: line 6: [: 2016-03-02: integer expression expected

marked as duplicate by Iain, Roman, yagmoth555, Diamant, Jenny D Mar 3 '16 at 11:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 5
  • 2
    Are you on the same course as Pawan ? It seems really odd that 2 independent people would come asking essentially the same question about something that isn't particularly common. – Iain Mar 2 '16 at 11:56
0
#!/bin/bash
cd /home/user1

current_date=$(date +%Y-%m-%d)

array=( 2016-03-02 2016-03-010 2016-05-10 )

for i in "${array[@]}"; do

    if [ "$current_date" == "$i" ];then

        echo "executing your bash script file";

        ./myscript.sh

    fi

done

Not the answer you're looking for? Browse other questions tagged or ask your own question.