我已经创建了一个脚本,可以将Terraform下载到我的服务器上并进行安装。
#!/bin/bash
wget https://releases.hashicorp.com/terraform/0.7.0/terraform_0.7.0_linux_amd64.zip
unzip terraform_0.7.0_linux_amd64.zip
echo "export PATH=$PATH:/root/terraform_dir" >> /root/.bash_profile
source /root/.bash_profile
terraform --version
这段代码运行良好。但是,一旦脚本完成并显示出来,.bash_profile
文件就会恢复其原始状态。即路径变量未更新。
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
当我给出terraform --version
外壳程序脚本之外时,它无法正常工作。
但是,当我给su -
,然后尝试时,terraform --version
它实际上可以正常工作。
是否有任何解决方法或自动脚本来更新.bash_profile
。我不想每次更新.bash_profile
?时都重新启动会话。
Shell脚本在子shell中运行(您在第一行中将其定义为#!/ bin / bash),环境中的任何更改都是该子Shell的本地内容,因此,bash_profile的来源仅影响该子Shell。
要在当前shell中执行命令,请使用source命令在当前shell中运行脚本(http://ss64.com/bash/source.html)
例如代替
$ ./myscript.sh
跑步:
$ source ./myscript.sh
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句