Hi folks,
I'm currently trying to figure out the possibilities of using functions within shell scripts.
Now I'm facing my first Problem
I'm trying to create a menu structure from where I can jump between different menues and always go back to my main menu ...
e.G.
-> Now the problem is, that I keep calling new functions without quitting the old function I'd like to leave and therefore continue to consume more memory on my machine each time I call another function. e.G.: jumping from main to function_1 and from there to main. After that I got 2xmain function active as well as 1xfunction_1 active. Then I jump to function_3 and back to main and voila: 3xmain active, 1xfunction_1 active AND 1xfunction_3 active ...
What would be the best way to end an old function as soon as I jump to another function ?
Regards
Thomas
I'm currently trying to figure out the possibilities of using functions within shell scripts.
Now I'm facing my first Problem
I'm trying to create a menu structure from where I can jump between different menues and always go back to my main menu ...
e.G.
Code:
#!/usr/bin/ksh
function main
{
echo "Please choose:"
echo "1) Do something"
echo "2) Do something else"
echo "3) Do something completely different"
echo ""
read $1
case $1 in
1) function_1
2) function_2
3) function_3
esac
}
function function_1
{
echo "Something ..."
... perform certain actions
echo "Press any key to return to main menu"
read $1
main
}
function function_2
{
echo "Something else ..."
... perform certain actions
echo "Press any key to return to main menu"
read $1
main
}
function function_3
{
echo "Something completely different..."
... perform certain actions
echo "Press any key to return to main menu"
read $1
main
}
main
-> Now the problem is, that I keep calling new functions without quitting the old function I'd like to leave and therefore continue to consume more memory on my machine each time I call another function. e.G.: jumping from main to function_1 and from there to main. After that I got 2xmain function active as well as 1xfunction_1 active. Then I jump to function_3 and back to main and voila: 3xmain active, 1xfunction_1 active AND 1xfunction_3 active ...
What would be the best way to end an old function as soon as I jump to another function ?
Regards
Thomas