Basic Shell Scripting
Your name here (please print):
Your student ID number here:
- (3 points) Understand what the command expr does. Then
write a bash script called interactive-product to
read in two numbers, one at a time, and then print their
product.
This script should work as follows:
[user@host name]$ ./interactive-product
Please enter the first number:
3
Please enter the second number:
7
The product is 21.
Write your script below.
#!/bin/bash
echo "Please enter the first number:"
read first
echo "Please enter the second number:"
read second
echo "The product is" `expr $first \* $second`
- (3 points) Make three files in your home directory:
John.1, John.2 and John.3. Use "vim" to put
the name John Donn in the first one, John Smith in the second and Mary
Ann in the third. Now write a bash script that searches for
"John" in files John.k, where k goes from 1 to 5.
Write it below.
#!/bin/bash
for i in `seq 1 5`
do
grep "John" John.$i
done
- (4 points) Modify the last bash script from your lecture to print
the output line in bold white font on green background. You will find
the rainbow.sh useful. Write the appropriate
echo command below.
echo -en "\033[1;37;42m"