Linux Quiz #006

Shell Calculator (Submit Answer)

This Linux Quiz once again calls for a shell script. Create a shell script that outputs the following when called with “–help” or “-h” as an argument:

Usage: mycalc OPERATOR FIRST SECONDWhere OPERATOR is one of add,subtract,multiply,divide
FIRST and SECOND are numeric

When the script is called with OPERATOR FIRST SECOND it should print the correct result. For example:

mycalc add 1 2

should print 3

mycalc divide 32 4

should print 8 and so on.

Extra Credit:
Design your script to accept parameterized arguments, such as –op=divide -f=1 -s=2, that can be entered in any order.

Leave a Reply