Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Linux and Unix Linux and Unix
Search Search
Search for:
Tech Support Guy > > >

Can anyone help me on my bsh shell script question. Thank you very much indeed!


(!)

seegu's Avatar
seegu seegu is offline
Junior Member with 6 posts.
THREAD STARTER
 
Join Date: Nov 2003
06-Nov-2003, 03:08 AM #1
Question Can anyone help me on my bsh shell script question. Thank you very much indeed!
How to write these shell scripts?

Menu options are as follows:

1.Lookup help on a command using man
2.Display file system disk space usage in megabytes
3.Display memory usage in megabytes with a line containing totals
4.List all current processes
5.Monitor top system processes
6.Display system uptime
7.Exit User Menu
Squashman's Avatar
Trusted Advisor with 19,643 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
06-Nov-2003, 03:18 AM #2
Why do you need this. Sounds like it would just slow a person down by using a menu to select from.
codejockey's Avatar
Senior Member with 1,405 posts.
 
Join Date: Feb 2002
06-Nov-2003, 03:48 AM #3
You will need some form of a while loop to control the overall logic (for example, a loop that executed as long as the selection was not "exit"). On each iteration of the loop, you will display the menu of choices, accept the user input, validate the input, and execute the associated command. When the command completes, control should return to the top of the loop (re-display menu, etc.).

Depending on how you choose to structure your program, you will need shell constructs such as while, read, if-then and case. Why not start with one of the options that you feel comfortable with, and write a script that will prompt for input ("should I execute this command Y/N?"), read and validate the response, and execute the command if requested. Once you've done one, you'll be well on your way to coding the complete menu system.

Hope this helps.
seegu's Avatar
seegu seegu is offline
Junior Member with 6 posts.
THREAD STARTER
 
Join Date: Nov 2003
06-Nov-2003, 06:21 AM #4
Quote:
Originally posted by LwdSquashman:
Why do you need this. Sounds like it would just slow a person down by using a menu to select from.
It is my linux exercise. i have to finish it by this week.
seegu's Avatar
seegu seegu is offline
Junior Member with 6 posts.
THREAD STARTER
 
Join Date: Nov 2003
06-Nov-2003, 06:26 AM #5
Quote:
Originally posted by codejockey:
You will need some form of a while loop to control the overall logic (for example, a loop that executed as long as the selection was not "exit"). On each iteration of the loop, you will display the menu of choices, accept the user input, validate the input, and execute the associated command. When the command completes, control should return to the top of the loop (re-display menu, etc.).

Depending on how you choose to structure your program, you will need shell constructs such as while, read, if-then and case. Why not start with one of the options that you feel comfortable with, and write a script that will prompt for input ("should I execute this command Y/N?"), read and validate the response, and execute the command if requested. Once you've done one, you'll be well on your way to coding the complete menu system.

Hope this helps.
Yes, it is help! thank you very much!!

Actually it's shame i dont know any about shell script, i just
started to learn linux last week. but i have to finish this
exercise by this week...so i quite worry
Squashman's Avatar
Trusted Advisor with 19,643 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
06-Nov-2003, 01:13 PM #6
I found this little menu driven script. You could probably edit it to do what you want it to do.
Attached Files
File Type: txt menu.txt (1.9 KB, 235 views)
codejockey's Avatar
Senior Member with 1,405 posts.
 
Join Date: Feb 2002
06-Nov-2003, 03:01 PM #7
I suspect that if you post your code and ask specific questions about whatever problems you are having, folks here will be more than happy to help. Good luck on your assignment -- Linux/Unix can be difficult to learn, but rewards careful study many times over.
seegu's Avatar
seegu seegu is offline
Junior Member with 6 posts.
THREAD STARTER
 
Join Date: Nov 2003
06-Nov-2003, 11:30 PM #8
I have just finished my script...but i dont know is it right.
Could anyone possible to check for me?
Thank you very much!!!
codejockey's Avatar
Senior Member with 1,405 posts.
 
Join Date: Feb 2002
07-Nov-2003, 01:55 AM #9
You can check for syntax errors by invoking your script as:

sh -n scriptname

and you can run your script with each line printing (with variable substitution) as it executes by invoking your script as:

sh -x scriptname

These are excellent debugging tools. If you are still having trouble, post your script with your specific question(s), and I'm sure you'll find people willing to help you.
seegu's Avatar
seegu seegu is offline
Junior Member with 6 posts.
THREAD STARTER
 
Join Date: Nov 2003
07-Nov-2003, 07:02 AM #10
Quote:
Originally posted by codejockey:
You can check for syntax errors by invoking your script as:

sh -n scriptname

and you can run your script with each line printing (with variable substitution) as it executes by invoking your script as:

sh -x scriptname

These are excellent debugging tools. If you are still having trouble, post your script with your specific question(s), and I'm sure you'll find people willing to help you.
I don't have linux at my machine, but i can try next monday at uni Cheers
seegu's Avatar
seegu seegu is offline
Junior Member with 6 posts.
THREAD STARTER
 
Join Date: Nov 2003
07-Nov-2003, 11:00 PM #11
Quote:
Originally posted by codejockey:
You can check for syntax errors by invoking your script as:

sh -n scriptname

and you can run your script with each line printing (with variable substitution) as it executes by invoking your script as:

sh -x scriptname

These are excellent debugging tools. If you are still having trouble, post your script with your specific question(s), and I'm sure you'll find people willing to help you.
Hv u seen my script? any suggestion?cheers
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




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


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑