[英]bash: Executing $0 when it is the result of a process redirection
我在GitHub上有一个脚本,该脚本通常由于流程重定向而执行,如下所示:
sh <(curl -sSL http://git.io/sinister)
如果脚本不是从Windows运行的,则脚本本身可能需要root特权,因此,我添加了以下代码行,以便在需要时以root身份重新执行自身:
on_windows()
{
uname | grep -q '[CYGWIN|MINGW|MSYS]'
}
if ! on_windows && [ "$USER" != 'root' ]; then
exec sudo "$0"
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.