时间之间的bash检查-有条件给出;“未找到”;

时间之间的bash检查-有条件给出;“未找到”;,bash,Bash,我有下面的代码,它在下面提供了相应的错误 #!/bin/sh H=$(date +%H) # If during sleeping hours (23 [or 11 pm] to 8 am), *don't* turn on the lights night_time=8 wake_up_time=23 if (( $H -le $night_time -o $H -le $wake_up_time )); then # Bedtime echo "You need to

我有下面的代码,它在下面提供了相应的错误

#!/bin/sh

H=$(date +%H)
# If during sleeping hours (23 [or 11 pm] to 8 am), *don't* turn on the lights
night_time=8
wake_up_time=23 
if (( $H -le $night_time -o $H -le $wake_up_time )); then 
    # Bedtime
    echo "You need to go to bed"
else
    echo "You're probably awake"
fi
错误:

/file_location/file.sh: 7: /file_location/file.sh 11: not found
所以,我似乎有问题的条件


是什么导致了这个错误?我在
和test之间添加了空格,并将它们作为算术括号
而不是括号
[
test
命令,因为我处理的是数字


我还缺少什么?

您可以使用测试或算术评估,但不要混淆它们

使用测试:

if [ "$H" -le "$night_time" -o "$H" -ge "$wake_up_time" ];
使用算术评估:

if (( "$H" <= "$night_time" || "$H" >= "$wake_up_time" ));
if(“$H”=“$wake\u up\u time”);

您使用了两次“小于或等于”,第二次可能应该是“大于或等于”。

将((和))更改为[]。对于程序员来说,您的时间限制是错误的;将23替换为1,将8替换为5。您有咖啡因可以让您继续前进!(当然,您还必须检查其余的比较逻辑。)