I want to display a numbered menu from a shell script (#!/bin/sh). Currently I use
To output the menu. Now I want to add a number prefix to each line so the result will look like:
How can I do this without having to manually prefix each line with a number? I'm thinking I want to iterate over the variable line by line and concatenate the line number and output it to a new variable.
If you are using
bash, I'd recommend using the
select built-in for these kind of tasks.
Here are some examples.
select is probably the way to go, but you could also do:
echo "$string" | nl -ba -s') '