LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Align Menu script (https://www.linuxquestions.org/questions/linux-newbie-8/align-menu-script-912988/)

geep1980 11-11-2011 05:43 AM

Align Menu script
 
I am creating a script that creates a Menu to go true.

I have done the following

Code:

seq -s ""#"" 70 | sed 's/[0-9]//g'
echo " "  | sed -e :a -e 's/^.\{1,65\}$/ & /;ta'  | sed 's/^/#/' | sed 's/$/#/'
echo "U heeft 1 van onderstaande mogelijkheden" | sed -e :a -e 's/^.\{1,65\}$/ & /;ta' | sed 's/^/#/' | sed 's/$/#/'
seq -s "-" 68 | sed 's/[0-9]//g' | sed 's/^/#/' | sed 's/$/#/'
echo " "  | sed -e :a -e 's/^.\{1,65\}$/ & /;ta' | sed 's/^/#/' | sed 's/$/#/'
echo -e "[1] Stoppen van de processen op \033[31malle servers \033[37m" | sed 's/^/#    /'| sed 's/$/#/'
echo -e "[2] Stoppen van de processen op enkele server" | sed 's/^/#    /' | sed 's/$/#/'
echo -e "[3] Starten van de processen op \033[31m alle servers \033[37m" | sed 's/^/#    /' | sed 's/$/#/'
echo "[4] Starten van de processen op 1 enkele server"  | sed 's/^/#    /' | sed 's/$/#/'
echo "[5] Een ander beheer script starten" | sed 's/^/#    /' | sed 's/$/#/'
echo -e "\033[33m \033[41m[A] Aanpassen file met alle servers \033[40m \033[37m" | sed 's/^/#  /' | sed 's/$/#/'
echo "[Q] Stop / Exit " | sed 's/^/#    /' | sed 's/$/#/'
echo  " "  | sed -e :a -e 's/^.\{1,65\}$/ & /;ta' | sed 's/^/#/' | sed 's/$/#/'
seq -s ""#"" 70 | sed 's/[0-9]//g'
echo -n "Maak uw keuze: "

The problem I have is that I want each line to start with the first 5 positions being "# " and al lines must end with a "#" at the same position (for example 78)

Can someone help me with my problem

unSpawn 11-11-2011 07:53 AM

Personally I wouldn't give a rats ass for eye-pleasing menus and simply use whatever BASH "select" prints to get the job done (unless your job is to look at preeeetty, preeeeeetty menus, that is ;-p). If you don't want use a CLI tool like 'dialog' (ncurses) then you'll probably want to use 'tput' as in http://wiki.bash-hackers.org/scripting/terminalcodes / http://tldp.org/LDP/abs/html/colorizing.html.

David the H. 11-11-2011 02:36 PM

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?

geep1980 11-17-2011 01:20 PM

It was a strugle and had help from your tips.

I have solved my problem.

Thank you.


All times are GMT -5. The time now is 08:33 PM.