实际上,我想创建一个日期数组并将其与今天的日期进行比较,如果它与当前日期匹配,则执行 test.sh 文件,否则退出 bash 脚本中的循环。我确实喜欢这个...
**#!/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
当我执行上述脚本时,它会出现类似./sample.sh: line 6: [: 2016-03-02: integer expression expected
答案1
#!/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