相关疑难解决方法(0)

Shell 命名空间

有没有办法将sourceshell 脚本放入命名空间,最好是 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

10
推荐指数
1
解决办法
8133
查看次数

标签 统计

shell ×1