1) Please specify the shell language you're using.
2) Effective use of whitespace, indenting, and comments help to make a script readable and more easily debuggable. Huge, unbroken blocks of commands are hard to decipher.
3) Try storing the raw text in variables, rather than echoing the strings directly. Then you can use the shell's built-in string manipulation
features to handle some of the text work.
4) Assuming bash or another shell that supports it, you can also probably use the printf
command to control formatting, rather than external tools like sed
5) Heck, why try to dynamically format it at all? Why not just build a static, or at least mostly static, menu? The less you can rely on external tools, the more efficient the script will be. You can store the pre-formatted menu in a here document
, and put it in a function to print it on demand. Another option could be to store it in an array with one line per element.
6) You might consider using dialog
instead. Why reinvent the wheel when there are already tools designed to do this for you?