
這是該內容的內容.gitignore
cron.yaml
build
target
webview
*.pyc
*.sublime-workspace
.idea
*.rej
.coverage
app/tools/temp_*.py
app/tools/*/temp_*.py
我目前正在透過此腳本迭代本地資料夾中的文件:
find . -type f | grep -v -E "(.idea|.git)" | while read file
do
# Do something with $file
done
我想進一步過濾這個$file
變量,如果它與.gitignore
.是否有任何現有實用程式或 bash 內建程式可以理解這些檔案模式?
答案1
您也許可以使用grep
's -f
aka ( --file
) 選項,透過過程替換來「正規化」某些模式。例如:
find . -type f | grep -Ev '(\.idea|\.git)' |
grep -v -f <(sed 's/\([.|]\)/\\\1/g; s/\?/./g ; s/\*/.*/g' .gitignore) |
while IFS= read -r file ; do
# Do something with "$file"
done