bash: 当它是进程重定向的结果时执行 $0

bash: Executing $0 when it is the result of a process redirection

我有一个脚本 on GitHub 通常作为进程重定向的结果执行,如下所示:

sh <(curl -sSL http://git.io/sinister)

脚本本身可能需要 root 权限,如果它不是 Windows 的 运行,所以我添加了以下代码行以在需要时以 root 身份重新执行:

on_windows()
{
    uname | grep -q '[CYGWIN|MINGW|MSYS]'
}

if ! on_windows && [ "$USER" != 'root' ]; then
    exec sudo "[=12=]"
fi

但是,这似乎不能顺​​利地与进程重定向一起使用。 运行 sh -x 结果是:

(trusty)james@localhost:~$ sh -x <(curl -sSL http://git.io/sinister)
+ set -e
+ ...
+ on_windows
+ grep -q [CYGWIN|MINGW|MSYS]
+ uname
+ [ james != root ]
+ exec sudo /dev/fd/63
sudo: /dev/fd/63: command not found

为什么会发生这种情况,我该如何解决?

您可能想查看这个答案:https://unix.stackexchange.com/a/156088

您可以尝试以下操作:将 curl 命令的结果存储在一个临时文件中并执行该文件。像这样:

curl -sSL http://git.io/sinister > file.temp
chmod u+x file.temp
./file.temp