簡體   English   中英

遍歷除某些文件以外的文件的腳本

[英]Script to loop through files except certain files

我試圖遍歷目錄中的所有HTML文件。

以下工作就可以了。

for f in *.html; do echo $f; done

但是,如何添加if條件,以便僅在不等於index.html文件名?

它應該像這樣簡單:

for f in *.html
do 
    if [ "$f" != "index.html" ]
    then
        echo $f
    fi
done
for f in *.html; do  [ "$f" != "index.html" ] && echo "$f"; done

也可以通過擴展的globbing從列表中完全排除index.html

shopt -s extglob nullglob
for f in !(index).html; do
    echo "$f"
done
  • shopt -s extglob :啟用擴展的shopt -s extglob
  • shopt -s nullglob :確保在沒有匹配文件的情況下不執行循環
  • !(index).html :擴展到所有不是index.html html文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM