为什么我的计数器坏了?


Why is my counter not working?

我有一个bash脚本,打算每15秒运行一个PHP脚本,每5分钟运行第二个PHP脚本。然而,我这样做的计数器不起作用。我找不到bug在哪里。

#!/bin/bash
while (true)
do
    sleep 1
    if (( count % 15 == 0 )) ;then
            php test.php
    fi
    if (( count % 300 == 0 )); then
            php test2.php
            count=0
    fi
     (( count = count +1 ))

done

当我运行这个脚本时,它在控制台中给我这个错误:

script.sh: 8: script.sh: count: not found
script.sh: 11: script.sh: count: not found
script.sh: 16: script.sh: count: not found
script.sh: 8: script.sh: count: not found
script.sh: 11: script.sh: count: not found
script.sh: 16: script.sh: count: not found

我尝试在循环之前实例化计数器,但它以相同的结果结束。任何帮助将非常感激!

您可能使用sh而不是bash执行脚本。确保使用./script.sh直接执行它(以便使用shebang二进制文件),或者使用bash bash script.sh

显式调用它。