Linux: function call in case

I am trying to set up a menu system where, when selected, it performs a function. In my case, the testfunc function is executed. However, this does not give an error; testfunc: command not found.

My case statement is as follows:

case "$mainMenuInput" in
   1)testfunc ;;
esac

function testfunc{
    echo "This is a test"
}

Thanks in advance.

+4
source share
1 answer

Shell scripts run at a time. A function is known only from the point that you define it. You must transfer it before calling.

+7
source

Source: https://habr.com/ru/post/1533335/


All Articles