在没有源命令的情况下将bash脚本作为源运行 [英] Run bash script as source without source command
本文介绍了在没有源命令的情况下将bash脚本作为源运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将脚本标记为作为源运行",所以您不必添加source
或."每次都命令它吗?即,如果我编写了一个名为"sup"的脚本,我想将其命名为
Is there any way to mark a script to be "run as source" so you don't have to add the source
or "." command to it every time? i.e., if I write a script called "sup", I'd like to call it as
sup Argument
而不是
source sup Argument
或
. sup Argument
基本上,我正在尝试在脚本中使用cd
.
Basically, I'm trying to use cd
within a script.
推荐答案
Bash会在它或您的内核甚至考虑它应该在其中做什么之前分叉并启动一个子Shell方式.这不是您可以撤消"的事情.所以不,这是不可能的.
Bash forks and starts a subshell way before it or your kernel even considers what it's supposed to do in there. It's not something you can "undo". So no, it's impossible.
非常感谢.
改为查看bash
函数:
sup() {
...
}
将其放入您的~/.bashrc
.
这篇关于在没有源命令的情况下将bash脚本作为源运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文