Write a script named lastname_firstname_checking.sh that does the following:
who
command and pipe it to grep).username is not logged on.
ps -aux and pipe it to grep.)
Write a “calculator” program in a script
named lastname_firstname_calculator.sh. This
script will ask users
to enter a simple expression of the form
number operator number, where the numbers
are integers and the operator is either
+, -, *, or /. If
the operator is not one of those four, you must produce an error message.
Your script must use the case construction.
In order to assign an asterisk * to a
variable without having
bash expand it as a pathname, you must put the following
line in your script before you start processing user input:
GLOBIGNORE='*'
date command like this:
month=$(date '+%B')
echo -n to keep the cursor on the same line as
your prompt.read to read the user’s input into a variable.awk command.
That command will set the awk delimiter string to '[+*/-]'.
(The dash
must come either first or last in the square brackets to avoid being
interpreted as a character range.)
The rest of the awk command will print field 1; that is the first number
in the input.
echo piped to awk exactly
as described previously, but print field 2; that is the second number in the input.
described above and have awk print field 2.
grep. Use the --only-matching option to grep
to extract the operator. Normally, grep echoes the entire line
when it finds a pattern; the --only-matching option shows only the part of the line that
matched. Example:
string1=$(echo "concatenate" | grep 'c[aeiou]t') string2=$(echo "concatenate" | grep --only-matching 'c[aeiou]t') echo "String 1 is $string1" echo "String 2 is $string2" cat
case statement to correctly set a variable named
result to the sum, difference, product, or quotient of the
two numbers. In the case statement, use the “default”
*) case to set result to an error message.
echo $result to display the answer (or error).
Here is sample output from several runs of the program. Your program does not have to give exactly these prompts and error messages, but it must exhibit similar behavior.
Enter expression: 3 + 5 8 Enter expression: 15 - 2 13 Enter expression: 12*144 1728 Enter expression: 1892/4 473 Enter expression: 3^2 Unknown or missing operator in 3^2
Make sure the script files are named in the form lastname_firstname_checking.sh and lastname_firstname_calculator.sh, and email them to the instructor. Put the word CIT052 in the subject line of your email, please.