有没有办法将source
shell 脚本放入命名空间,最好是 bash shell 脚本,但如果其他 shell 具有此功能而 bash 没有,我会查看它们。
我的意思是,例如,诸如“在所有定义的符号前面加上一些东西,这样它们就不会与已经定义的符号(变量名、函数名、别名)发生冲突”或任何其他防止名称冲突的工具。
如果有一个解决方案,我可以在source
时间(NodeJS
样式)中命名空间,那将是最好的。
示例代码:
$ echo 'hi(){ echo Hello, world; }' > english.sh
$ echo 'hi(){ echo Ahoj, sv?te; }' > czech.sh
$ . english.sh
$ hi
#=> Hello, world
$ . czech.sh #bash doesn't even warn me that `hi` is being overwritten here
$ hi
#=> Ahoj, sv?te
#Can't use the English hi now
#And sourcing the appropriate file before each invocation wouldn't be very …
Run Code Online (Sandbox Code Playgroud) shell ×1