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?

1 Answers1

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.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • 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? – Bartek Lachowicz Apr 13 '23 at 12:56
  • I don't understand the question. A common hack is to mark things as pseudo-private by prefixing them with underscores. – tripleee Apr 13 '23 at 12:58
  • 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. – Bartek Lachowicz Apr 13 '23 at 13:18