简单的bash脚本不起作用

胡德卡苏沙尔

我对bash脚本非常陌生。我正在尝试制作一个脚本来导出http_proxy变量。这是我在终端上所做的:

$export http_proxy=http://proxy21.iitd.ernet.in:3128/
$export https_proxy=https://proxy21.iitd.ernet.in:3128/

这样很好。现在,这是我的脚本(称为setproxy):

#!/usr/bin/env bash
if [ $1 -eq 22 ]
then
    export http_proxy=http://proxy22.iitd.ernet.in:3128/
    export https_proxy=https://proxy22.iitd.ernet.in:3128/
elif [ $1 -eq 21 ]
then
    export http_proxy=http://proxy21.iitd.ernet.in:3128/
    export https_proxy=https://proxy21.iitd.ernet.in:3128/
elif [ $1 -eq 61 ]
then
    export http_proxy=http://proxy61.iitd.ernet.in:3128/
    export https_proxy=https://proxy61.iitd.ernet.in:3128/
elif [ $1 -eq 62 ]
then
    export http_proxy=http://proxy62.iitd.ernet.in:3128/
    export https_proxy=https://proxy62.iitd.ernet.in:3128/
fi

本质上,我想根据输入设置适当的代理服务器。我将其放在bin文件夹中,使其可执行,然后将bin添加到路径中,然后登录和注销。终端接受setproxy作为有效命令(至少没有找到命令错误),但是,当我这样做时:

$setproxy 22

没有效果。代理保持不变。我究竟做错了什么?

疾病

调用脚本时,将调用一个新的子外壳程序来运行它。它的代理已设置,但是不能从子进程更改父进程(您的shell)的代理。尝试寻找脚本,例如调用它

. setproxy 21

然后,脚本将由您当前的shell解释。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章