Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Unix Scripting Each of these scripts are separate and unrelated. Please write ea

ID: 3800240 • Letter: U

Question

Unix Scripting
Each of these scripts are separate and unrelated. Please write each of these scripts in: a.) Bourne Shell, b.) C-Shell, c.) Korn Shell, and d.) Z Shell.

5. Write a script that uses a switch or case statement (depending on shell) to do the following. First ask the user for a color. If they enter anything that begins with bl or Bl, then print the sky color is (whatever the user entered). If the user enters red or yellow, the print the sun is sometimes this color. If the user enters any other color, then enter that the color is not in any of the categories defined.

6. Write a simple while loop which prints out numbers from 0 through 9 using the @ operator and a variable. In case of Bourne shell, use the expr command to increment the loop variable.

7. Write a script called days which is run as follows from the command line: days Monday Tuesday Wednesday Thursday Friday Saturday Sunday
and it prints out the days in the following way:
Monday Tuesday Wednesday Thursday Friday Saturday Sunday
Tuesday Wednesday Thursday Friday Saturday Sunday
Wednesday Thursday Friday Saturday Sunday
Thursday Friday Saturday Sunday
Friday Saturday Sunday
Saturday Sunday
Sunday

8. Write a script that takes in two arguments that are positive integers. The script should figure out which of the two integers is smaller and should use that to figure out the greatest common divisor (GCD) of the two integers and print it out. Also, figure out the lowest common multiple (LCM) of the two integers and print it out.

Explanation / Answer

Hi,

Here's my 2 cents to the best of my ability -

5. Colors

#!/bin/sh
echo "Please enter a color: "
read color
case "$color" in
"red") echo "The sun is sometimes red." ;;
"yellow") echo "The sun is sometimes yellow." ;;
bl*) echo "The sky is $color" ;;
   Bl*) echo "The sky is $color" ;
   *) echo "This color is not in any of the defined categories.";;
esac

6. Simple Loop - Numbers 0-9

a. ------BASH Shell------
#!/bin/bash
num = 0
while [$num -lt 10]
do
echo $num
((num++))
done

b. ------Bourne Shell------
num = 0
while [$num -lt 10]
do
   echo $num
   num = 'expr $num + 1'
done

c. -----Korn Shell-----
#!/bin/ksh
num = 0
while [[$num -lt 10]]; do
echo $num
((num++))
done

d. -----C Shell-----
#!/bin/csh
num = 0
while ($num <10)
   echo $num
@num = $num + 1
end

8. GCD and LCM of two numbers

echo "Enter first number: "
read num1
echo "Enter second number: "
read num2

if [$num1 -gt $num2]
then
number = $num1
denominator = $num2
else
number = $num2
denominator = $num1
fi
remainder = 'expr $number % $denominator'
while [remainder -ne 0]
do
number = $denominator
denominator = $remainder
remainder = 'expr $number % $denominator'
done
GCD = $denominator
LCM = 'expr $num1 * $num2 / GCD'
echo "GCD is $GCD"
echo "LCM is $LCM"

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote