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

Question : Point out error(s) if any, add comments , and briefly explain what do

ID: 3778148 • Letter: Q

Question

Question: Point out error(s) if any, add comments, and briefly explain what does the script do?

#!/bin/bash

C1=”b”

C2=”F”

”STRING”= S1

S2=”string”

S3=               ”Some darn string”

if [[ $C1 > $C2 ]];   then

                echo “$C1 is greater than $C2”

else

                echo “$C1 is less than $C2”

fi

if [[ $S1 > $S2 ]]; then

                echo “ $S1 is greater than $S2”

                echo “ $S1 is less than $S2”

fi

if   [[ -n $S3 ]]; then           # __-n ?_______________________________

                echo “ S3 is $S3”

else

                echo “ S3 is empty”

fi

if   [[ -z $S4 ]]; then           # __-z ?_________________________________

                echo “ S4 is empty”

else

                echo “ S4 is $S4

fi

Answers the question above in details, thank you.

Explanation / Answer

#!/bin/bash
# your code goes here
C1=”b”
C2=”F”
S1=”STRING” # corrected the wrong way of assigning value ”STRING”= S1
S2=”string”
S3= ”Some darn string”

if [[ $C1 > $C2 ]]; then
echo “$C1 is greater than $C2”
else
echo “$C1 is less than $C2”
fi

if [[ $S1 > $S2 ]]; then
echo “ $S1 is greater than $S2”
else # else was missing so two statements were getting printed
echo “ $S1 is less than $S2”
fi

if [[ -n $S3 ]]; then # __-n ?_check if $S3 is of non zero length
echo “ S3 is $S3”
else
echo “ S3 is empty”
fi
if [[ -z $S4 ]]; then # __-z ? check if variable is of zero length
echo “ S4 is empty”
else
echo “ S4 is $S4
fi

output:

In this code ,four if statements are used.In the first if , b and F are compared . As F is greater than b ,it is checked.

In the next if , two strings , STRING and string are compared.

In the third if the length of variable is checked if it is non zero which is false.

In the last if , the variable is checked if it is of zero length which is true.

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