[英]source ~/.bashrc from bash script does not work
I am trying to create a script to be reload bashrc once but it did not work. 我正在尝试创建一个脚本来重新加载bashrc一次,但是它不起作用。
#!bin/bash
source ~/.bashrc
rm reloader.sh
You need to use source
to run the script: 您需要使用
source
来运行脚本:
source reloader.sh
If you just run it as a command, it will run in a new process, so none of the changes that .bashrc
makes will affect your original shell process. 如果仅将其作为命令运行,它将在新进程中运行,因此
.bashrc
所做的任何更改都不会影响您的原始Shell进程。
I had the same problem. 我有同样的问题。 The issue is that only interactive shells can access whatever you have defined in your
.bashrc
(Aliases and so on) 问题在于,只有交互式外壳程序才能访问您在
.bashrc
定义的任何内容(别名等)。
To make your shell-script interactive use a shebang with parameter: 要使您的shell脚本具有交互性,请使用带参数的shebang:
#!/bin/bash -i
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.