Unix/Lunix Programming Exercise 5 Read the following script interactive_mode and
ID: 3904391 • Letter: U
Question
Unix/Lunix Programming
Exercise 5
Read the following script interactive_mode and answer the question.
# interactive mode
if [[ -n $interactive ]]; then
while true; do
read -p "Enter name of output file: " filename
if [[ -e $filename ]]; then
read -p "'$filename' exists. Overwrite? [y/n/q] > "
if [[ "$REPLY" == "y" ]]; then
break
elif [[ "$REPLY" == "q" ]]; then
echo "Program terminated."
exit
fi
elif [[ -z $filename ]]; then
continue
else
break
fi
done
fi
Assume that interactive is not empty.
What are the next five commands that will be executed if user provides an empty filename?
What is the next three commands being executed if user supplies a non-existing filename?
What is the next two commands being executed if user supplies an existing filename?
If user then provides ‘n’, what are the next three commands being executed?
Exercise 6 (The complete code of sys_info can be found in the D2L Content.)
Read the following piece of codes and answer the question.
if [[ -n $filename ]]; then
if touch $filename && [[ -f $filename ]]; then
write_sys_info > $filename
else
echo "$PROGRAM: Cannot write file '$filename'" >&2
exit 1
fi
else
write_sys_info
fi
Which of the following commands would lead to the execution of else clause above?
sys_info -f output -i
sys_info
sys_info -i
sys_info -f output
Explanation / Answer
the next five commands are if the user provide empty file names
the code should give output that file name is missing
for non existing files the output should be file is not present at specific location.
if [[ "$REPLY" == "y" ]]; then
break
elif [[ "$REPLY" == "q" ]]; then
echo "Program terminated."
exit
fi
sys_info -f output -i
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.