Unix Assignment Question 1. Explain the function of break and continue commands
ID: 3587654 • Letter: U
Question
Unix Assignment
Question 1. Explain the function of break and continue commands in UNIX/Linux.
Question 2. Name two commands that are used in bash script to perform arithmetic calculations. Describe the difference between them.
Question 3. Explain what is happening in Lines 1, 4, 9, and 18. What is the output of this operation?
Line 01: $ x=5
Line 02: $ y=3
Line 03: $
Line 04: $ if [ $x -lt $y ]
Line 05: > then
Line 06: > echo " "
Line 07: > echo " ${x} is less than ${y}"
Line 08: > echo " "
Line 09: > elif [ $x -eq $y ]
Line 10: > then
Line 11: > echo " "
Line 12: > echo " ${x} is equal to ${y}"
Line 13: > echo " "
Line 14: > else
Line 15: > echo " "
Line 16: > echo " ${x} is greater than ${y}"
Line 17: > echo " "
Line 18> fi
Question 4. Which of the following programming constructs can be used in a bash shell script:
a. if…do statement
b. case command
c. for...do loop
d. while…do loop
e. until…done loop
Explanation / Answer
Question 1:-
Break command in linux is used to stop the loop execution i.e. whenever break command is encountered all the statements upto the break is executed and once break command is encountered the execution immediatly comes out from the loop and follows the next statement after the loop.
Continue is also same as Break but with a minor difference in the working method i.e whenever the compiler encounters the continue statement it immediatly stops the current iteration of the loop and will start the new iteration without exiting from the loop.
Question 2:-
Let command is used to make arthametic caluculations and to store the result in variable.
expr is the command used to make arthametic calculations.
The difference between this two is the Let command the calculation will be done and the result will be stored in the given variable. But in the expr command the result of calculation will be printed directly.
Question 3:-
In the first 5 values is assigned to the variable x.
In the fourth line It checks condition whether the x is less than y (-lt is less than ).
In the Ninth line it enters into elif condition it means elseif , If condition is satisfied then it enters into elif and then here it checking x is equal to y.
In the bash script if is closed with fi which indicates the end of the if loop.
The output of this operation is 5 is greater than 3.
Question 4:-
b. case command
case command is used in bash script for switching purpose.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.