如何在bash中隐藏私有函数不让用户看到?

huangapple go评论56阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年4月13日 20:28:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76005442.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定