Luca Borrione
Luca Borrione

Reputation: 17022

how to make a function readonly

Having a sample function

function functionName ()
{
    echo "Hello World"
}

How can I avoid it to be overwritten by a following function with the same name?

function functionName ()
{
    echo "this is another function"
}

Upvotes: 4

Views: 1685

Answers (1)

Luca Borrione
Luca Borrione

Reputation: 17022

You need to use the -f option to make corresponding function readonly and syntax is:

readonly -f functionName

After this, if you ever try to update the function an error will be fired:

bash: functionName: readonly function

Upvotes: 8

Related Questions