Sunday, April 28, 2024
29
rated 0 times [  29] [ 0]  / answers: 1 / hits: 47727  / 2 Years ago, thu, march 10, 2022, 11:44:46

I'm setting up a shell script with menues and sub menues, options, etc. But on each menu/submenu/etc, i need a "Go back to main menu" choice.



I've already got the menu set up and it works fine, but i need a way to simply restart the script from scratch, reset all variables etc etc.



Or a way to exit the current script and starting it again.



I've tried to do this:



ScriptLoc=$(readlink -f "$0")
./ScriptLoc


But that starts the "new" script inside the "old" script, so when i exit the "new" script, it goes back to the "old" script (if that makes any sense). It's a script inside a script kind of thing.



Anyone got an idea how to restart it completely?


More From » command-line

 Answers
5

Yes, do



exec "$ScriptLoc"


The exec bash builtin command replaces the current program with a new one.


[#29066] Saturday, March 12, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sconhoney

Total Points: 403
Total Questions: 118
Total Answers: 109

Location: Andorra
Member since Mon, Jan 9, 2023
1 Year ago
sconhoney questions
;