I have a shell script which conditionally calls a function.
For Example:-
if [ "$choice" = "true" ]
then
process_install
elif [ "$choice" = "false" ]
then
process_exit
fi
process_install()
{
commands...
commands...
}
process_exit()
{
commands...
commands...
}
Please let me know how to accomplish this.
You don’t specify which shell (there are many), so I am assuming Bourne Shell, that is I think your script starts with:
Please remember to tag future questions with the shell type, as this will help the community answer your question.
You need to define your functions before you call them. Using
():Then you can call your functions, just as if you were calling any command:
You may also wish to check for invalid choices at this juncture…
See it run with three different values of ${choice}.
Good luck!