Search code examples
bashshunsetbash-function

unset bash function variable with non-standard name


I may have this function in a bash script that gets sourced to the shell

function suman{
     echo "using suman function"
}

if I call

unset suman

things seem to work as expected

however if I have this as my function:

function suman-inspect {
     echo "using suman-inspect function"
}

then if I call

unset suman-inspect

or

unset "suman-inspect"

I get this message:

bash: unset: `suman-inspect': not a valid identifier

How can unset this variable as is?


Solution

  • After some more research, it appears that

    unset -f "suman-inspect"
    

    will work. This is surprising because unset suman did work, and did successfully unset the suman function (as far as I could tell).