1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

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

Discussion in 'Linux and Unix' started by seegu, Nov 6, 2003.

Thread Status:
Not open for further replies.
Advertisement
  1. seegu

    seegu Thread Starter

    Joined:
    Nov 6, 2003
    Messages:
    6
    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
     
  2. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    Why do you need this. Sounds like it would just slow a person down by using a menu to select from.
     
  3. codejockey

    codejockey

    Joined:
    Feb 11, 2002
    Messages:
    1,405
    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.
     
  4. seegu

    seegu Thread Starter

    Joined:
    Nov 6, 2003
    Messages:
    6
    It is my linux exercise. i have to finish it by this week. :(
     
  5. seegu

    seegu Thread Starter

    Joined:
    Nov 6, 2003
    Messages:
    6
    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:confused:
     
  6. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    I found this little menu driven script. You could probably edit it to do what you want it to do.
     

    Attached Files:

  7. codejockey

    codejockey

    Joined:
    Feb 11, 2002
    Messages:
    1,405
    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.
     
  8. seegu

    seegu Thread Starter

    Joined:
    Nov 6, 2003
    Messages:
    6
    I have just finished my script...but i dont know is it right.
    Could anyone possible to check for me?
    Thank you very much!!!
     
  9. codejockey

    codejockey

    Joined:
    Feb 11, 2002
    Messages:
    1,405
    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.
     
  10. seegu

    seegu Thread Starter

    Joined:
    Nov 6, 2003
    Messages:
    6
    I don't have linux at my machine, but i can try next monday at uni:( Cheers
     
  11. seegu

    seegu Thread Starter

    Joined:
    Nov 6, 2003
    Messages:
    6
    Hv u seen my script? any suggestion?cheers
     
  12. Sponsor

As Seen On
As Seen On...

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.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/177342