"Quoting within quoting" 自称 bash 深情的问题

"Quoting within quoting" question for professed bash affectionate

出于纯粹的好奇心,我想知道如何解决这种引用困境。 我已经通过绕行解决了这个问题(我将 [vcodec!*=av01] 添加到 -f 参数并完全删除了 --exec 部分)。否则,它 仅在 --exec 参数中没有空格或减号 时有效。 罪魁祸首是最后一行,问题在 --exec 参数的最后。其他的可以忽略。

感谢您在悟道上的帮助! ;-)

#!/bin/bash

trap "exit" INT

avtomp4conv () {
  # tests if the given file (in argument) is an AV1 media and if so, converts it to mp4
  echo ""
  if ($( ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "" | grep -i av > /dev/null )); then
    echo " bad codec"
    ffmpeg -hide_banner -loglevel error -stats -i "" -movflags faststart -preset ultrafast "${1%.mp4}_fixed.mp4" && mv "" bogus/ && mv -n "${1%.mp4}_fixed.mp4" ""
  fi
}

# ... lotsa other stuff ...

export -f avtomp4conv
cat links.txt | parallel -u -I % --retries 3 --max-args 1 --jobs 4 python3 `which youtube-dl` -c -f "'bestvideo[height<=720][ext=mp4]+bestaudio[ext=m4a]/mp4'" --external-downloader aria2c --external-downloader-args "'-x 4 -s 4'" --exec \'bash -c \"export -f avtomp4conv\;avtomp4conv \{\}\"\' %

使用另一个函数将您从单个命令中的双重间接寻址中拯救出来(parallel 执行 youtube-dl,然后执行 avtomp4conv)。 GNU parallel 使用你当前的 shell 来执行它的命令,所以这里不需要 bash -c

avtomp4conv () {
   ...
}
ytdl() {
   youtube-dl ... --exec "bash -c 'avtomp4conv \"[=10=]\"' {}"
}
export -f avtomp4conv ytdl
< links.txt parallel ... ytdl

如果没有 ytdl 函数,您可以尝试以下操作。但为什么要为这些嵌套引号烦恼呢?

< links.txt parallel ... -I insteadOf{} \
"youtube-dl ... --exec \"bash -c 'avtomp4conv \\"$0\\"' {}\""