0

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?

0

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for this comment. Side question: What is the standard way to implement super_tools when I want to implement it by extracting functionality in functions yet make them inaccessible for the user? Is it unsetting?
I don't understand the question. A common hack is to mark things as pseudo-private by prefixing them with underscores.
I am new to bash maybe that's why I cannot ask about the right things but I think I am good to go now. Thanks again. I was basically wondering if it's possible to somehow totally hide local functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.