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

Bash - file path can not be read for LAME encoder

如何正确地转义从 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

returns

lame: excess arg Island of the Gods - 3.mp3

使用 Bash for 循环是 not ideal for the results of find or ls. There are 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