如何正确地将find
出来的路径转移到新的命令参数?
#!/bin/bash
for f in $(find . -type f -name '*.flac')
do
if flac -cd "$f" | lame -bh 320 - "${f%.*}".mp3; then
rm -f "$f"
echo "removed $f"
fi
done
返回
lame: excess arg Island of the Gods - 3.mp3
答案 0 :(得分:1)
对for
或find
的结果使用Bash ls
循环为not ideal。有other ways to do it。
您可能希望使用-print0
和xargs
来避免分词问题。
$ find [path] -type f -name *.flac -print0 | xargs -0 [command line {xargs puts in fn}]
或者在查找中使用-exec
primary:
$ find [path] -type f -name *.flac -exec [process {find puts in fn}] \;
或者,您可以使用while
循环:
find [path] -type f -name *.flac | while IFS= read -r fn; do # fn not quoted here...
echo "$fn" # QUOTE fn here!
# body of your loop
done