在Bash中模拟do-while循环的最佳方法是什么?
我可以在进入while
循环之前检查条件,然后在循环中继续重新检查条件,但这是重复的代码。有更简洁的方法吗?
我的脚本的伪代码:
while [ current_time <= $cutoff ]; do
check_if_file_present
#do other stuff
done
如果在$cutoff
时间之后启动,则此操作不执行 check_if_file_present
,而使用do-while则会执行。
until
开关吗? - Mike Gardneruntil
在执行循环体之前会评估条件。 - Alex