![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2004
Posts: 3
Rep Power: 0
![]() |
Hello......I am new to this forum and also new to scripting. I am very familiar with DOS batch files and would like to do some similar things in Linux. I am using Knoppix 3.7. I have been reading alot of websites offering help and tutorials on scripting but cannot find exactly what i want to do. I understand the basic idea of creating the script in editor and then making it executable. Basically I want to do is not too complicated i hope.
For example, I have a directory that contains roughly 50 text files on various subjects of interest. I would like to make a menu showing maybe 20 choices of those text files. I want to assign a letter to each choice and have the file that is chosen to be displayed on screen and then a provision to exit the displayed file and return to menu..... Is there a basic scripting routine that will let me do this??? I have done this extensivly in DOS using colors and graphics. I also want to be able to do this using a command line only computer eventually. Well for now I will use the Konsole. After using Linux now for 8 months, I realize the power of scripting and i think its fun. I just need some help getting started....I do not need to "test conditions" or do any of that "if" business because I know the files i have are where they belong and do not need to test if they are or are not existing. The next thing i would like to learn is how to use colors in my menus and so on......if anyone has the time to help me a little at a time that would be great! thank you...bob |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
look into using the case statement....
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Oct 2004
Posts: 3
Rep Power: 0
![]() |
Hello....I did look up in Google the "case" statement but did not find anything that made sense to me. I am not a programmer so it was hard to follow. I did find a site that showed a little of what I know and made sense to me, but i am still lost as far as where to begin. I did see a little on making a box putting some text in it but i need EXAMPLES!
Someone out there must have done what I am trying to do! I could not find how to actually make the script work....I keep thinking in the way of DOS batch files. Just a simple sample would help and I can build on it from there. Thats how I learned it in DOS, by copying alot of examples and experimenting. What I want is something like this: **************************************** * M A I N M E N U * * * * A) Packet Radio Program * * B) Telnet * * C) Frequency List [text file] * * D) Radio Instruction [text file] * * * * Q) quit to prompt * * * ************************* *************** This is VERY BASIC.....and then, once this is saved as a file, how do you go about getting this menu to display and get the choices to bring up the desired program or file? Like if I press "D" I want the text file on radio instructions to display. Then when I read it, how do i return to menu? Do you have to press your letter choice and then "ENTER"? In my batch files I use errorlevels and only need to press the letter of the program/file i want. If i can figure this out, i can build it up to be better, with colors and so on.......I need step by step help if someone has the time. thanks...bob ps i know this border of stars looks a little hacked up.....there are supposed to be stars on right border! They all ended up on left. And I dont know why smily is in the way! |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
Merry Christmas...
- You can execute the programs or anything else you need to do in this script, just add the line(s) in the appropiate section before the ;; #!/bin/sh echo "A) Packet Radio Program" echo "B) Telnet" echo "C) Frequency List" echo "D) Radio Instruction" echo "" echo "Q) Quit to Prompt" while : do *read INPUT_STRING *case $INPUT_STRING in * A) * * *echo "Packet Radio Program" * *;; * B) * * *echo "Telnet!" * *;; * C) * * *echo "Frequency List" * *;; * D) * * *echo "Radio Instruction" * *;; * Q) * * *echo "Exiting!" * * *break * *;; * *) * * *echo "Sorry, I don't understand" * *;; *esac done echo echo "program terminated."
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#5 |
|
PFO Founder
![]() ![]() |
just kind of curious but is there away to force a bash script to run everytime someone logs in via ssh or telnet. and is there away to make to make it take up the whole screen so that all that is seen is the menu.
or would something like this be better done in a different language thanks. im just kind of curious on this ![]()
__________________
BIG K aka Kyle Programming Forums Kyle K Online Please do not PM or email me programming questions. Post them in the forums instead. |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Oct 2004
Posts: 3
Rep Power: 0
![]() |
OK so you mean for example the double semi colon, ";;" is where you would put the PATH of the program / file you want to run? For example, to display "frequency list" which is choice "C", i would put in front of those double semi colons the path of that particular file, such as: /home/bob/textfiles/freq.txt freq.txt being the text file shown on the menu as choice C.
Are the double semi colons like a LABEL in DOS bat files? I am just confused as to where the reference is to the path for each selection. Whew this is harder than i thought! Well thats what these forums are for, right? |
|
|
|
|
|
#7 |
|
Programming Guru
![]() ![]() ![]() |
I'm sure that can be done... either with a call to the script within their profile or calling the script from a program that listens for those connection types on the appropiate ports.
I'm not sure if you could center the menu on the screen (you probably can)... but it all else fails, you can clear the screen before displaying the menu or limite their access to certain directories and run the menu script upon their login via their account's profile.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#8 |
|
Programming Guru
![]() ![]() ![]() |
No. The ;; ends the case value block.
Put your call to your to the program / file above the ;;. For instance: C) echo "Frequency List" more /home/bob/textfiles/freq.txt freq.txt ;;
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|