This quiz is part of the DevOpsTheHardWay course.

Please answer the quiz and click the "Test" button at the bottom right.

Bash - loops - multichoice questions

Given the following script, answer the following 3 questions:

[elvis@station elvis]$ cat script
#!/bin/bash

for i in $*
do
  if [ -r $i ]
  then
    gzip $i
  else
    echo "cannot compress $i"
  done
fi

[elvis@station elvis]$ ./script rotate_cw
./script: line 10: syntax error near unexpected token `done'
./script: line 10: `
done'

Question 1

Which of the following lines could replace the line if [ -r $i ] above, with no effect on script execution?

Question 2

What syntax error exists in the script?

Question 3

What does the variable i iterate through (assuming the syntax error mentioned above is fixed)?

Question 4

The following text is found in the file /etc/bashrc.

if [ "$(id -gn)" = "$(id -un)" -a "$(id -u)" -gt "99" ]; then
  umask 002
else
  umask 022
fi

Which of the following best describes the execution of this text?

Question 5

The following text is found in the file /etc/profile.

for i in /etc/profile.d/*.sh ; do
  if [ -r "$i" ]; then
    . $i
  fi
done

Which of the following best describes the execution of this text?

Question 6

The following text is found in the file /etc/profile.

for i in /etc/profile.d/*.sh ; do
  if [ -r "$i" ]; then
    . $i
  fi
done

What innocent action could a system administrator make that causes an error (exit status other than 0) when this section of the above script is executed?

license