Bash - command techniques
Please answer the quiz and click the "Test" button at the bottom right.
Question 1
Which of the following commands would create a file called jan_reports.txt?
-
MONTH=jan; touch ${MONTH}_report.txt -
MONTH=jan; touch $MONTH_report.txt -
MONTH= jan; touch $MONTH_report.txt -
MONTH= jan; touch $"MONTH"_report.txt - A and B
Question 2
Which command would display the current shell's process id (pid)?
-
echo $$ -
echo $! -
echo $PID -
echo $BASH_PID - None of the above
Question 3
When used from within a script, which variable contains the name of the script?
-
$0 -
$# -
$$ -
$@
Question 4
After running a command line from an interactive bash prompt, the following messages are displayed:
bash: timelog: Permission denied
timestamp failed
Which of the following command lines could have produced the messages?
-
date >> timelog || echo timestamp failed -
date >> timelog && echo timestamp failed -
date >> timelog ; echo timestamp failed - A and C
- All of the above
Question 5
Which of the following would run the chmod command only if the mkdir command succeeds?
-
mkdir mail || chmod 700 mail -
mkdir mail && chmod 700 mail -
mkdir mail ; chmod 700 mail -
mkdir mail | chmod 700 mail - None of the above
Question 6
Which of the following would run the chmod command only if the mkdir command fails?
-
mkdir mail | chmod 700 mail -
mkdir mail && chmod 700 mail -
mkdir mail ; chmod 700 mail -
mkdir mail or chmod 700 mail - None of the above
Question 7
When the user plato runs the following command, what is the name of the file that is written to?
cal > calendar.$(id -un).txt`
-
calendar.txt -
calendar.pluto.txt -
calendar.id-un.txt -
calendar.512.txt - None of the above