Results 1 to 5 of 5
Hi all, i am new to Linux and i am not even a good programmer. I was wondering if there is a possibility to create a bash script for a ...
- 06-10-2007 #1Just Joined!
- Join Date
- Jun 2007
- Posts
- 5
Help for a menu that read the option from a txt file
Hi all, i am new to Linux and i am not even a good programmer. I was wondering if there is a possibility to create a bash script for a menu, with sub-menus, that read the description of the options to choose and the actions to do from a text file.
My problem is that the users have to use a command that read a file that corespond to the option, so for them it would be easier to modify the text file that should contain description and name of the file.
Basically the script should create a menu that read from a file that contain something like this:
Main Menu
submenu 1
1)Option A -- File A
2)Option B -- File B
submenu 2
1)Option C -- File C
2)Option D -- File D
Of course the Main Menu should contain just Submenu1 and submenu2 and when one of those menu is choosen, the user can see the options of the submenu.
Thank You for any help
Gabe
- 06-12-2007 #2Just Joined!
- Join Date
- Jun 2007
- Posts
- 5
Is there someone who can tell me at least (as i am new) the commands i should study and use in my script to read variables from a file?
Thank you
- 06-13-2007 #3Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Here's an example:
Bash Menu Program - SBLUG
Regards
- 06-13-2007 #4
It's a bit difficult to help you Lele, as I'm not really sure what you want. Adding variables to a menu is very well possible, assigning variables from output of files is too, so combine this et voila!
How to build a menu, the previous poster gave an excellent link. I use a different style, but that's a matter of taste.
How to assign variables, I assume you know.
Reading variables from files is a bit more complex (but not more difficult is the design behind those files is predictable)
Just 'sed', 'grep' or 'awk' the file, 'cut' the things you don't need, 'sort' them if need be, and 'uniq' the double entries out of there. Embrace them with whatchacallid, these: ``
For example:
Mind you, this does not assign $VAR to be "data", rather $VAR will be the entry in the third column (; as seperator in this example) in a line that contains "data".Code:VAR=`grep data file | sort | cut -d; -f3 | uniq`
So in a line:
date; data; var; list goes on forever.
$VAR will be "var"
- 06-13-2007 #5Just Joined!
- Join Date
- Jun 2007
- Posts
- 5


Reply With Quote
