Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux: Calling a function within a case

I am trying to set up a menu system where on selection it runs a function. In my case is runs the 'testfunc' function. However is it fails giving the error; testfunc: command not found.

My case statement looks like this;

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

function testfunc{
    echo "This is a test"
}

Thanks in advance.

like image 271
Seatter Avatar asked Feb 14 '23 10:02

Seatter


1 Answers

Shell scripts are executed statement at a time. The function is only known from the point you define it. You have to move it before the call.

like image 112
Jan Hudec Avatar answered Feb 19 '23 10:02

Jan Hudec