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

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!