英文:
How to hide private functions from the user in bash?
问题
After sourcing the following code, my terminal is able to see the "__hey" function.
super_tools() {
case "$1" in
"hey")
__hey
;;
*)
echo "Invalid argument: $1"
;;
esac
}
function __hey() {
echo "hey"
}
我想要防止这种情况发生,以便用户只看到"super_tools",然后可以进一步提供"hey"。是否可以在不取消函数的情况下实现这一点?
英文:
After sourcing the following code my terminal is able to see __hey
function.
super_tools() {
case "$1" in
"hey")
__hey
;;
*)
echo "Invalid argument: $1"
;;
esac
}
function __hey() {
echo "hey"
}
I would like to prevent that from happening so that the user only sees super_tools
and can provide it further with hey
. Is it possible to do this without unsetting function?
答案1
得分: 1
抱歉,我只会回应您的翻译请求。以下是您要翻译的内容的中文翻译:
没有,在shell中没有私有或隐藏函数的概念。要使某些内容可运行,它需要在命名空间中可见。
有一些工具可以混淆shell脚本,但它们基本上相当于将代码编译成本机二进制代码,虽然可能会有点繁琐,但不一定难以反汇编。
英文:
No, there is no concept of private or hidden functions in the shell. In order for something to be runnable, it needs to be visible in the namespace.
There are tools to obfuscate shell scripts, but they basically amount to compiling the code into a native binary which is tedious, but not necessarily hard, to disassemble.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论