Linux Shell Scripting III
Procedure
You will create a script file to perform basic calculations.
1. Create a script file called mycalc.sh using vim.
2. The first line of your script file should force the use of the bash shell.
3. At the header of the script file there should be a section of comments that contains the
following
a. assignment number
b. your name and student number
c. lab section number
d. name of the script file
e. the date
f. a description of what the script file does
4. Your script file should be properly commented throughout the script.
5. The script file should perform the following operations: '+' and '-' (addition and subtraction).
6. The script should have two functions:
a. Each named add and subtract
b. Each of the functions should accept two integer numbers as parameters
c. The functions should perform the desired algebraic operation
7. The script file should support two modes of operation, either with no parameters or
with three parameters.
a. If three parameters are provided, the second parameter must be + or - :
The first and third parameters must be numbers.
The user can enter integer numbers only.
The result should be displayed on the screen and the program exit.
The example below demonstrates how the plus operation should work. Do a
similar operation for '-'
Example:
mycalc 12 + 3
The sum of 12 plus 3 equals 15
b. If no parameters are provided the script should do the following:
A menu should be provided allowing the user to either Exit or Do a
Calculation. Allow upper or lower case menu selections. See Menu 1 below.
Menu 1
C) Calculation
X) Exit
If 'C' menu option is selected from Menu 1, the screen should clear and the
user should be prompted to enter a number. See Menu 2 below.
You don’t need to check if the input numbers are integers
Menu 2
Please enter an integer number or X to exit:
If a number is entered into Menu 2, the screen should clear and a new menu
should be displayed. See Menu 3 below.
Menu3
+) Add
- ) Subtract
X) Exit
If + or - is entered the screen should clear and the user should be prompted to
enter a second number. See Menu 2 above.
If a second number was entered the calculated result should be displayed on
the screen.
After three seconds the screen should clear and Menu 1 should be displayed
again.
c. Error checking should be done to make sure of the following:
Either no parameters or three parameters are entered.
If three parameters are entered then the second parameter must be one of
the following + or -.
Any invalid choices in the menu system should be recognized/identified, and
the user should be presented the menu item again.
You don’t need to check if the input numbers are integers.
版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。