Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"
}
like image 239
Luca Borrione Avatar asked Oct 11 '25 21:10

Luca Borrione


1 Answers

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
like image 180
Luca Borrione Avatar answered Oct 14 '25 16:10

Luca Borrione



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!