我想循环遍历目录中的一系列文件,然后在目录为空时退出。如何使用ls退出bash循环?
在$工作“MYPROG”实际上是一个程序,处理(和档案)传入的电子邮件中的Maildir中的100
批我简单的东西,我可以投入的cron后。
#!/bin/bash
# Setup
mkdir -p foo && touch foo/file_{1,2,3,4}.txt
alias myprog='f=`ls foo/file_*.txt | head -n1`; rm -v $f'
# Loop and then exit ?!
# This line to go into cron.
while (ls foo); do ls foo/ | wc -l; myprog; sleep 1; done
任何想法?
你可以在大括号扩展中做范围:'{1..4}' –
甚至更好,你可以是PORTABLE并使用适当的通配符'file_ [1234]'。 :) – vladr