我想循環遍歷目錄中的一系列文件,然後在目錄爲空時退出。如何使用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