Newbie bash help
I'm writing a script for an install and need help with a menu. I'm really new with scripting and I'm still learning syntax and commands.
I'd like for this menu to return after I've edited a particular config file. And also when pressing 0 it will continue the script without exiting bash. A loop seems in order here still confused with "Do's and While's", and maybe some suggestions or examples on cleaning this up. Thx Code:
#Time to Edit .conf files ... |
Perhaps you should look into the case statement, this is the absolute perfect place to use one ...
http://www.grymoire.com/Unix/Sh.html#uh-82 So in your case start with: Code:
case $CONF in |
Absolutely perfect... this will help with another menu I'm working on... Though I might have another question... Even though this command is straight forward.
Thx |
Would something like this work... Or do i need to 'break' after each edit, for it to return to the menu? I tried just this bit of code and I can edit my files but it breaks back into prompt after exiting nano. I'd like it to return back to the original menu to continue edit
Code:
echo "Time to edit your files for install and your conf.d files" Thanks again for that website.. easier to understand then this other site I'm using. |
Nope, you don't need the break statement, since break is meant to exit from within a for, while, until, or select loop. See man bashbuiltins for more details. H_TeXMeX_H maybe put it thinking at C language, where indeed the break statement is mandatory.
If you want to return to the original menu after editing, you have to envelope the code within a while loop, testing for the value of CONF and executing the loop until the user selects 0 (exit). For example: Code:
#!/bin/bash |
So... Nice.... I was experimenting with a the while loop before you posted. This example will help immensely with my other menus. Quick question on syntax?
And if I exclude then "done" at the end of the loop, will it continue on... This is just an excerpt of an overall script. I still need the program to continue after I press 0. Code:
while [ $CONF -ne 0 ] FYI I get this for the man you posted: Quote:
Forgive any novice ignorance... BTW, this code was most helpful... learned alot from this. Code:
read -p "Enter selection (0-5), and then press enter: " CONF |
Quote:
Quote:
Quote:
Quote:
Code:
while [ -ne 0 ] |
Thanks for the help.... I figured out how to break the loop and continue... Using the last posters tutorial link..
|
All times are GMT -5. The time now is 11:31 PM. |