gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 10:42:21 25 4
gpt4 key购买 nike

我有一个脚本 on 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

关于linux - bash:当它是进程重定向的结果时执行 $0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34480708/

25 4 0
文章推荐: linux - 从 bash 脚本中发送到后台的进程中检索退出代码
文章推荐: javascript - 如何在
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com