[英]Linux Script, for on files of a directory
我需要執行一個Shell腳本,該腳本在目錄中文件上方放置一些參數。
我正在使用類似的東西
for f in *.tmp
do
echo $f
sleep 5
done
我的問題是在for的執行過程中,目錄中文件的數量可能會更改。 並且for僅適用於首次執行時列出的文件。
有任何想法嗎 ?? 非常感謝!
您可以將文件存儲在數組中
files=(*.tmp)
然后使用無限的while循環,並在滿足條件時中斷:
i=0
while true; do
do_something with "${files[i]}"
current_files=(*.tmp)
magic_handwaving -- some code to compare "files" with "current_files" \
that will append new files to "files"
(( ++i == ${#files[@]} )) && break
done
echo all files processed
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.