Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to hide private functions from the user in bash?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading