I am trying to unset function using be searching for all of them and then looping to unset them with no luck
Non loop way works (example where bar_ is created and unset)
function bar_ { echo "bar"; }
function_name="bar_"
echo -n "before unset found function: --> "
declare -F $function_name || echo "<not found>"
unset -f $function_name
echo -n "after unset found function: --> "
declare -F $function_name || echo "<not found>"
echo ""
However when unsetting in a loop, it fails to remove itself
function foo_ { echo "bar"; }
declare -F | cut -d" " -f3 | grep foo_ | while read function_name
do
echo -n "before under found function: --> "
declare -F $function_name || echo "<not found>"
unset -f ${function_name}
done
echo -n "after unset found function: --> "
declare -F foo_ || echo "<not found>"
echo ""
Is this some scope issue? I tried wrapping the unset statement in eval to no effect.
The problem here is not the loop, but the pipe. Try it this way:
This uses bash process substitution.
Alternatively you could use a temporary file or a coprocess here.