我試圖構建一個涉及find
的長命令。我有一組我想忽略的目錄,我想將這個目錄格式化爲命令。Bash數組:追加和預先考慮到數組中的每個元素
基本上,我想這個數組轉換:
declare -a ignore=(archive crl cfg)
成這樣:
-o -path "$dir/archive" -prune -o -path "$dir/crl" -prune -o -path "$dir/cfg" -prune
這樣一來,我可以簡單地將目錄添加到陣列,以及find
命令將相應調整。
到目前爲止,我想出如何在前面或使用
${ignore[@]/#/-o -path \"\$dir/}
${ignore[@]/%/\" -prune}
追加,但我不知道如何將這些結合起來,同時前插和追加到一個數組中的每個元素。
聽起來很不錯。我認爲你需要有多個級別(副本)的數組來支持每個$ {var/x/y}替換。我使用'$(echo $(echo $ {ig [@]} | sed's/a/b/g; s/c/d/g; s/d/e $ /; s/^ f/g /'))'。祝你好運! – shellter