gpt4 book ai didi

linux - 将 shell 脚本通过管道传输到 bash 并启动交互式 bash

转载 作者:太空狗 更新时间:2023-10-29 11:37:35 25 4
gpt4 key购买 nike

考虑 example.com 上的以下 shell 脚本

#/bin/bash

export HELLO_SCOPE=WORLD
eval $@

现在,我想下载并以最简单的方式执行带有参数的 shell 脚本,并能够启动带有 HELLO_SCOPE 变量集的交互式 bash 终端。

我试过了

curl http://example.com/hello_scope.sh | bash -s bash -i

但它会立即退出 shell。据我所知,这是因为脚本 curls stdout 仍然是 bash 的 stdin,阻止它以交互方式启动(因为这需要我的键盘是 标准输入)。

有没有一种方法可以避免这种情况,而无需执行使用 shell 脚本创建临时文件的额外步骤?

最佳答案

你可以source它:

# open a shell
. <(curl http://example.com/hello_scope.sh)
# type commands ...

关于linux - 将 shell 脚本通过管道传输到 bash 并启动交互式 bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23935465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com