Unix Assignment 1. Explain the difference between && and ||. 2. What command can
ID: 3587655 • Letter: U
Question
Unix Assignment
1. Explain the difference between && and ||.
2. What command can be used to take the place of several nested if statements in a bash shell script
3. What command ends every do loop in a while…do statement? What command ends an until…do statement?
4. Write a script that checks the user’s home directory for a file named hw5file. Assuming it’s present, append the file with, “Today’s date is mm/dd/yy”. If you can’t locate the file hw5file, then create it and store, “This is username on computer_name making my first entry.”
Explanation / Answer
1. && is AND operator. This operator is used when we want some statements to be executed only when all the required conditions are satisfied. So even if one conditions fails, the statements will not be executed if we use && operator.
|| is OR operator. This operator is used when we want some statements to be executed if at least one of the conditions is statisfied. So if we use || operator, then even if many conditions fail, but if there is at least one condition that is satisfied, statements will be executed.
2. Nested if statements can be replaced by case statements. For example:
#!/bin/bash
# case example
case $1 in
apple)
echo apple
;;
orange)
echo orange
;;
banana)
echo banana
;;
*)
echo unknown
;;
esac
3. Both while...do and until...do statements end with the command "done".
Syntax of do...while loop is:
while
do
statement 1
statement 2
statement 3
...
statement n
done
And syntax for until...do loop is:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.