I've got a bash script that writes to a file. at the end of the script I want to display a menu, with line numbers - and have the user be able to select 1 or 2, (etc. up to the number of lines in the file) then have it execute that line.
Up to here is perfect.
However, after the line is executed (say for example it displays another file.) I'd like to return to the menu and let the user select another number. Including zero for exiting the menu.
Once the menu is displayed I have the following. (dumpline being the line of the file read)
dresult=`sed -n "$dumpline"p "$PWD"/"$myday1"_"$myjob".txt`
$dresult
But right now - after running the variable $dresult - it exits the shell (where instead I'd like the menu displayed.
Any thoughts?
thank you in advance.
I think, you need something like a loop. Here is a small skelleton for executing a selected line from file:
But be aware of the following:
Here's another way to do a menu which relies on
cat
having the ability to number the lines of a file (some versions ofcat
may not have that - see the second example if this is the case). Both examples are for a simple four-item menu:This doesn't require
cat -n
:My comments on dz's answer are too long for a comment, so I'm posting them here:
Using
seq
withselect
would make a redundant-looking menu, with no correlation between it and the display of the lines in$dumpfile
:You could do something like this instead: