如何在 bash 中对用户隐藏私有函数?

问题描述 投票:0回答:1

获取以下代码后,我的终端可以看到

__hey
功能。

super_tools() {


    case "$1" in
        "hey")
            __hey
            ;;
        *)
            echo "Invalid argument: $1"
            ;;
    esac
}


function __hey() {
        echo "hey"
    }

我想防止这种情况发生,以便用户只能看到

super_tools
并可以进一步提供
hey
。是否可以在不取消设置功能的情况下执行此操作?

bash private-members bash-completion private-methods
1个回答
1
投票

不,shell 中没有私有或隐藏函数的概念。为了使某些东西可以运行,它需要在命名空间中可见。

有混淆 shell 脚本的工具,但它们基本上相当于将代码编译成本机二进制文件,这很繁琐,但不一定很难反汇编。

© www.soinside.com 2019 - 2024. All rights reserved.