Bash - LAME编码器无法读取文件路径

时间:2017-07-07 22:22:13

标签: bash lame

如何正确地将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

1 个答案:

答案 0 :(得分:1)

forfind的结果使用Bash ls循环为not ideal。有other ways to do it

您可能希望使用-print0xargs来避免分词问题。

$ 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