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

Unix/Lunix Programming Exercise 2 Read the following script posit_param2 and ans

ID: 3904390 • Letter: U

Question

Unix/Lunix Programming

Exercise 2

Read the following script posit_param2 and answer the question.

count=1

while [[ $# -gt 0 ]]; do

    echo "Argument $count = $1"

    count=$((count + 1))

    shift

done

What are the values of # and count before and after the execution of while loop?

                        before              after

#

count

What are the first 4 lines of the outputs if the command posit_param /* is executed?

Exercise 3

Read the following script sys_info_func and answer the question.

# sys_info_func: program to output a system information page                                                          

TITLE="System Information Report For $HOSTNAME"

CURRENT_TIME=$(date)

TIMESTAMP="Generated $CURRENT_TIME, by $USER"

report_uptime () {

   echo "System Uptime"

   uptime

}

report_disk_space () {

   echo "Disk Space Utilization"

   df -h

}

report_home_space () {

   echo "Home Space Utilization ($USER)"

   du -sh $HOME

}

write_sys_info () {

echo "$TITLE"

echo "$TIMESTAMP"

report_uptime

report_disk_space

report_home_space

}

write_sys_info

What is the sequence of function calls that occur during the execution of the script?

Explanation / Answer

Exercise 2:

The value of # before the while loop is equal to the number of the command line arguments passed to it.

The value of # is decremented by '1' every time the while loop is executed and the while loop is iterated until the value of # equals zero.

So the value of # is number of command line arguments passed to it and the value of # after the while loop is 0.

The value of count before the while loop is executed is one and it is equal to (number of arguments+1) after the while loop is executed.

The first four lines of the outputs when the command posit_param /* is executed are the first four directories in the root folder '/' .

Exercise 3:

First the function write_sys_info_is called. The first two echo statements in the write_sys_info are printed onto the console, followed by the three function calls of the functions "report_uptime","report_disk_space" and "report_home_space".

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