我有一段代码,用来判断是否是周末,如果不是周末,它会打印一行代码。但是,我在第二个if语句中遇到错误。以下是我的代码
#!/bin/sh
# A daily reminder service
set `date`
echo "Remember for today:"
if [ $1 == "Sat" ] | [ $1 == 'Sun' ]
then
echo "it is the weekend"
else
if [ "5:55:00" < $4 < "6:05:59" ]
then
echo "get up"
elif [ "6:55:00" < $4 < "7:05:59" ]
then
echo "have breakfast"
elif [ "7:55:00" < $4 < "8:05:59" ]
then
echo "start the first class"
elif [ "21:55:00" < $4 < "22:05:59" ]
then
echo "time to do homework"
else
echo "There's nothing for you to do!"
fi
fi我的错误如下所示
[cpm1051@srvlp-dpt-cs01 labfifteen]$ ./dailyReminder
Remember for today:
./dailyReminder: line 9: 10:29:33: No such file or directory
./dailyReminder: line 12: 10:29:33: No such file or directory
./dailyReminder: line 15: 10:29:33: No such file or directory
./dailyReminder: line 18: 10:29:33: No such file or directory
There's nothing for you to do!我不确定它在寻找什么文件?它已经捕获了日期。我做错了什么?
任何帮助都将不胜感激!
发布于 2021-04-07 01:16:33
您可以尝试拆分它们并使用" and“运算符:
if [[ "14:55:00" < $4 ]] & [[ $4 < "18:05:59" ]]确保使用双方括号[[]],并在它们之前和之后保留一个空格。
https://stackoverflow.com/questions/66970367
复制相似问题