Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 5th, 2004, 7:42 PM   #1
bob58
Newbie
 
Join Date: Oct 2004
Posts: 3
Rep Power: 0 bob58 is on a distinguished road
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
bob58 is offline   Reply With Quote
Old Oct 5th, 2004, 9:01 PM   #2
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Oct 6th, 2004, 7:56 AM   #3
bob58
Newbie
 
Join Date: Oct 2004
Posts: 3
Rep Power: 0 bob58 is on a distinguished road
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!
bob58 is offline   Reply With Quote
Old Oct 6th, 2004, 9:54 AM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Oct 6th, 2004, 11:57 AM   #5
big_k105
PFO Founder

 
big_k105's Avatar
 
Join Date: Mar 2004
Location: Fargo, ND
Posts: 1,667
Rep Power: 10 big_k105 is on a distinguished road
Send a message via AIM to big_k105 Send a message via MSN to big_k105 Send a message via Yahoo to big_k105
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.
big_k105 is offline   Reply With Quote
Old Oct 6th, 2004, 12:20 PM   #6
bob58
Newbie
 
Join Date: Oct 2004
Posts: 3
Rep Power: 0 bob58 is on a distinguished road
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?
bob58 is offline   Reply With Quote
Old Oct 6th, 2004, 12:25 PM   #7
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Oct 6th, 2004, 12:27 PM   #8
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:43 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC