Linux urgent question please answer ASAP
- Your menu will be surrounded by a loop, either the until or while loop, so that when one option is concluded it will go back to the main menu until the user selects an option x to exit. Try NOT TO USE THE EXIT command to quit the script, use the proper logic of the loop control to exit the program. Also using while : or while true or until true, etc. is not a good loop logic. You have a menu so, the exit should be an option in the menu such as, when option <> q, etc.
- Program in one file
- Menu example:
- email:~> bash menu_script.sh
- Command Menu
- a. Emailer Program
- b. Users Currently Logged On
- c. Current Date and Time
- d. This months Calendar
- e. name of the Working Directory
- f. Contents of the Working Directory
- g. Find the IP of a Web Address
- h. See your Fortune
- i. Print a file (on the screen)
- j. Exit
- Please select a letter:
- Here is samples interaction with the emailer portion of the program. There is no need to display the calendar or show a list of available files to attach.
- Please select a letter: a (this would go to the option for the emailer program that you created)
- Welcome user
- Today is: date
- This is this months Calendar:
- February 2005
- Su Mo Tu We Th Fr Sa
- 1 2 3 4 5
- 6 7 8 9 10 11 12
- 13 14 15 16 17 18 19
- 20 21 22 23 24 25 26
- 27 28
- This program will allow you to send a message,
- with a file attachment, to any selected user.
- Please enter the subject of your message and press <enter>: Test message
- Please enter the email address of the recipient and hit <enter>:
- Please enter the file to be attached to this message and press <enter>.
- please choose a file: testfile
- Then it would got back to the main menu
1) Lack of comments on your program
2) Use of meaningful variable names
3) #!/bin/bash should be the first line of our program.
4) Using the option read -n1 varname allows you to tap on “one key to continue”
5) Many commands might produce a full screen of output and you will not be able to see the what was on the top, always | more
6) Use the command clear to clear the screen and have a non-cluttered output. =======================
7) Use the logic of the loop to get out of the loop, using exit 1 or exit 0 still terminates the program but you are forcing the end of the program instead of using the logic of a loop
8) There are many ways to implement the until loop, but you need to make sure to use the proper operator and initialize the variable before it is checked in the until loop. Otherwise the comparison condition may always be true or false. Same not as above, use the logic of the loop to end it.
9) Consider using functions. They will be easier to troubleshoot if your program does not work and it organizes your program
10) Initialize your variables to a value.
11) Test you emailer.
12) Binary logic. Remember that when you do binary logic you are always comparing two items. For instance if a > b then .. you do not use if a > b > c, you need to break it down into if a > b and a > c