![작동하지 않는 변수와 함께 find 사용 [중복]](https://linux55.com/image/210107/%EC%9E%91%EB%8F%99%ED%95%98%EC%A7%80%20%EC%95%8A%EB%8A%94%20%EB%B3%80%EC%88%98%EC%99%80%20%ED%95%A8%EA%BB%98%20find%20%EC%82%AC%EC%9A%A9%20%5B%EC%A4%91%EB%B3%B5%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