【发布时间】:2018-07-02 09:46:33
【问题描述】:
所以我是 bash 的新手,我必须制作一个脚本,其中包含动态回显的行,并带有不断变化的时间戳 HH:MM。 所以当我给说
sh run.sh 03:40 05:40
它应该在给定范围之间的所有时间回显 例如:03:31 03:32 ........ 05:39 05:40
我知道循环非常简单,但我无法弄清楚。有什么帮助吗?
我有这个不太好的代码,现在还不能工作。
echo "Enter from Hour:"
read fromhr
echo "Enter from Min:"
read frommin
echo "Enter to Hour:"
read tohr
echo "Enter to Min:"
read tomin
while [ $fromhr -le $tohr ]; do
while [ $frommin -le $tomin ]; do
echo "$fromhr:$frommin"
if [ $frommin -eq 60 ]; then
frommin=0
break
fi
((frommin++))
done
if [ $fromhr -eq 24 ]; then
fromhr=0
fi
((fromhr++))
done
【问题讨论】:
-
将您的时间转换为纪元时间戳,增量,以您想要的格式打印。
标签: linux bash shell loops while-loop