![動作しない変数で find を使用する [重複]](https://linux33.com/image/210107/%E5%8B%95%E4%BD%9C%E3%81%97%E3%81%AA%E3%81%84%E5%A4%89%E6%95%B0%E3%81%A7%20find%20%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%99%E3%82%8B%20%5B%E9%87%8D%E8%A4%87%5D.png)
配列で宣言されていないファイルをインポートするには、findコマンドを使用する必要があります。
# ALLOWED extensions
ext_allowed=("*.cs" "*.csproj" "*.sln" "*.json")
combined=""
for ext in "${ext_allowed[@]}"; do
combined="$combined -not -name \"$ext\""
done
# This doesn't work :(
find $location $combined -not -type d
# This does work, but it looks the same??
find $location -not -name "*.cs" -not -name "*.csproj" -not -name "*.json" -not -name "*.sln" -not -type d
変数の位置は単にファイルの場所を保持します。 -o オプションも試してみましたが、やはり動作しません。
誰でも私を助けることができますか?ありがとう
答え1
文字列を作成する代わりにcombined
配列にします。
for ext in "${ext_allowed[@]}"; do
combined+=($ext)
done
その後、パラメータ拡張を使用する必要があります。 (望むよりhttps://wiki.bash-hackers.org/syntax/pe#search_and_replace)
find "$location" "${combined[@]/#/'-not -name '}" -not -type d