1

我想创建一个临时的shell 脚本,并将其作为参数传递给另一个脚本,即回调挂钩。是否可以为此使用流程替换?

在这个例子中,aria2c允许一个钩子作为参数。下载页面后,aria2c 将使用一些参数调用该钩子。理想情况下,我希望 aria2c 调用我的“虚拟”脚本,而无需先制作任何临时文件,如下所示:

aria2c \
  --on-download-complete <(echo '#!/bin/sh'; echo 'echo "Called with [$1] [$2] [$3]"') \
  https://aria2.github.io/

但结果我得到一个许可错误:

Could not execute user command: /dev/fd/63: Permission denied
4

1 回答 1

0

正如评论中所指出的,aria2c希望钩子参数是作为回调执行的程序的文件名。但是,进程替换产生的文件名不是这样的程序;进程替换返回命名管道的文件名

如果不创建任何文件,您将无法做您想做的事。但是,单个静态帮助程序和导出的 bash 函数变得接近:

/my/odc/helper

#!/bin/bash
__aria2c_odc_helper_function "$@"
exit

用作类似的东西:

__aria2c_odc_helper_function(){
    echo "Called with [$1] [$2] [$3]"
}
export -f __aria2c_odc_helper_function

aria2c --on-download-complete /my/odc/helper \
    https://aria2.github.io/
于 2020-02-07T00:52:07.457 回答