DAT2330 Practice Final Exam - Ian Allen - Winter 2003 DAT2330 - Ian Allen - Winter 20-1- 0 minutes Evaluation: 57 Questions Name: _________________________ Important Instructions 1. Read all instructions and both sides of all pages. 2. Manage your time when answering questions on this test. Answer the questions you know, first. (Office use only: 43 29 37 14 34 23 2 21 31 36 33 44 22 1 30 49 54 53 50 11 18 10 39 16 19 52 17 48 51 26 42 32 41 20 46 35 9 7 8 25 47 27 12 57 38 13 6 24 55 4 3 15 56 45 40 5 28) 1. What is the bash output of this sequence of two commands: x=';' ; echo one $x date a. one ; date b. one ';' date c. one $x date d. one ; Mon Sep 30 08:00:00 EDT 2002 e. one followed by Mon Sep 30 08:00:00 EDT 2002 on a new line 2. If foo is a script containing the line TERM=vt100 ; export TERM, what is the output of the following sequence of bash commands: TERM=linux ; ./foo ; echo $TERM a. vt100 b. TERM c. foo d. $TERM e. linux 3. Given the following bash shell command line: read a b c, which user keyboard input line below will assign the text b to the shell variable named b? a. a b c b. a,b,c c. a;b;c d. a=a b=b c=c e. a:b:c 4. What is the output of the following sequence of bash commands: a=1 ; b=2 ; test $a -ge $b ; echo $? a. the number 1 or 0 followed by another 1 or 0 on a new line b. 0 c. no output d. test: $a: integer expression expected e. 1 5. If variable bar might contain nothing (a null value - defined but empty), which bash command sequence correctly tests for this and prints YO? a. if [ $bar -eq "" ] ; then echo YO ; fi b. if [ "$bar" = * ] ; then echo YO ; fi c. if [ "$bar" = "" ] ; then echo YO ; fi d. if [ $bar -eq : ] ; then echo YO ; fi e. if [ ''$bar'' = '''' ] ; then echo YO ; fi 57 QuestionsDAT2330 Test #3 - Practice Unix Final - 0% 0 minutes DAT2330 - Ian Allen - Winter 20-2- 0 minutes 6. Which bash command sequence correctly searches for the string and then prints OK if it is found inside the password file? a. if test string /etc/passwd ; then echo OK ; fi b. if [ grep string /etc/passwd ] ; then echo OK ; fi c. if [ test string /etc/passwd ] ; then echo OK ; fi d. if test string = /etc/passwd ; then echo OK ; fi e. if grep string /etc/passwd ; then echo OK ; fi 7. What is the output of the following sequence of bash commands: cd /etc && echo "in $(pwd)" a. no output b. in 0pwd) c. bash: cd: /etc: No such file or directory d. in /etc e. in $(pwd) 8. Which bash command sequence correctly compares the two numbers and prints OK? a. if ( let 4 > 3 ) ; then echo OK ; fi b. if [ 4 > 3 ] ; then echo OK ; fi c. if [ ! 4 <= 3 ] ; then echo OK ; fi d. if ( ! 4 < 3 ) ; then echo OK ; fi e. if [ 4 -gt 3 ] ; then echo OK ; fi 9. What is the output of the following sequence of bash commands: echo wc >wc ; wc wc >wc ; cat wc a. wc b. 1 1 2 wc c. 1 1 3 wc d. 0 0 0 wc e. no output 10. Which line below passes three separate arguments to the sort command when placed inside a shell script named foo invoked by the command line: ./foo a b c a. sort "$*" b. sort "$? $? $?" c. sort "$1 $2 $3" d. sort "$@" e. sort "$#" 11. A shell script named bar is executed as follows: ./bar a "b c" 'a ' Inside the script is the line: argv.sh $@ What is the count of arguments that the argv.sh command will display? a. 6 b. 3 c. 2 d. 4 e. 5 57 QuestionsDAT2330 Test #3 - Practice Unix Final - 0% 0 minutes DAT2330 - Ian Allen - Winter 20-3- 0 minutes 12. What is the bash output of this command sequence: false && echo "Hello There" a. Hello There b. HelloThere c. no output d. Hello There e. "Hello There" 13. If x=5 and y=5, which bash command sequence correctly compares the two numbers as equal and prints OK? a. if ( x == y ) ; then echo OK ; fi b. if [ $x==$y ] ; then echo OK ; fi c. if test x -eq y ; then echo OK ; fi d. if [ x = y ] ; then echo OK ; fi e. if test $x -eq $y ; then echo OK ; fi 14. If bar is an executable script containing the line foo=dog then what is the bash output of this sequence of three commands: foo=cat ; ./bar ; echo "the '$foo' ate" a. the '$foo' ate b. the 'dog' ate c. the 'foo' ate d. the 'cat' ate e. the $foo ate 15. If x=8 and y=9 then which of the following bash command lines outputs only the word foobar (and nothing else)? a. [x -ne y] || echo foobar b. [x!=x] || echo foobar c. [ x -ne y ] && echo foobar d. [ x = x ] && echo foobar e. [!x = y] && echo foobar 16. What is the bash shell output of this two-command sequence: cd /home/alleni && echo "In $(pwd)" a. In $(pwd) b. "In $(pwd)" c. In 0pwd) d. In /home/alleni e. no output 17. In an empty directory, how many files will be created using the following bash shell two-command sequence: x='12 3 4 5' ; touch $x a. 1 file b. 4 files c. 2 files d. 5 files e. 3 files 57 QuestionsDAT2330 Test #3 - Practice Unix Final - 0% 0 minutes DAT2330 - Ian Allen - Winter 20-4- 0 minutes 18. In an empty directory, what is the bash shell output of this three-command sequence: touch aa .a ab .b .c ; x='.a* .b*' ; echo '$x' a. .a .b b. $x c. '.a* .b*' d. .a* .b* e. aa .a ab .b 19. Select the correct bash shell order of command line processing: a. aliases, variables, globs, redirection b. redirection, aliases, globs, variables c. aliases, globs, variables, redirection d. aliases, redirection, variables, globs e. aliases, variables, redirection, globs 20. Which of these commands makes a file owned by me, also executable by me? a. chmod x+u myfile b. chmod x=u ./myfile c. chmod u+x ./myfile d. umask 111 myfile e. umask 777 myfile 21. If a=cow and b=dog then what is the output of the following sequence of bash commands: [ $a = dog -o $b = dog ] && echo $? a. 1 b. the number 1 or 0 followed by another 1 or 0 on a new line c. test: $a: integer expression expected d. 0 e. no output 22. Which of these first lines will cause this executable file to be interpreted using the Bash shell? a. #!/bin/bash b. #/bin/bash c. !/bin/bash d. !#/bin/bash -u e. /bin/bash -u 23. What is the bash shell output of this two-command sequence if run in a directory containing 9999 files with names that are all the numbers from 1 to 9999 inclusive: x="*" ; echo "$x" a. the file names 1 through 9999, surrounded by quotes b. "$x" c. the file names 1 through 9999 d. * e. $x 57 QuestionsDAT2330 Test #3 - Practice Unix Final - 0% 0 minutes DAT2330 - Ian Allen - Winter 20-5- 0 minutes 24. If a=cow and b=dog then what is the output of the following sequence of bash commands: [ $a = dog -o $b = cow ] ; echo $? a. the number 1 or 0 followed by another 1 or 0 on a new line b. 1 c. 0 d. no output e. test: $a: integer expression expected 25. If a=cow and b=dog then what is the output of the following sequence of bash commands: if $a = $b ; then echo $a ; fi a. bash: cow: command not found b. test: $a: integer expression expected c. cow d. test: cow: integer expression expected e. no output 26. In an empty directory, what is the bash shell output of this three-command sequence: touch aa .a ab .b ac .c ; x='a* b*' ; echo "$x" a. a* b* b. $x c. aa ab ac b* d. aa ab e. *a *b 27. If a=cow and b=dog then what is the output of the following sequence of bash commands: [ $a = cow -a $b = cow ] ; echo $? a. no output b. test: $a: integer expression expected c. the number 1 or 0 followed by another 1 or 0 on a new line d. 1 e. 0 28. What is the bash shell output of this command sequence: true && echo Hello There $? a. Hello There ? b. no output c. Hello There ? d. Hello There 0 e. Hello There 1 29. In an empty directory, what is the bash shell output of this three-command sequence: touch aa .a ab .b ac .c ; x='*a *b' ; echo $x a. a* b* b. aa ab c. $x d. *a *b e. aa ab ac b* 57 QuestionsDAT2330 Test #3 - Practice Unix Final - 0% 0 minutes DAT2330 - Ian Allen - Winter 20-6- 0 minutes 30. If foo is a script containing the line TERM=new ; export TERM, what is the output of the following sequence of bash commands that use foo: TERM=bar ; ./foo ; echo $TERM a. new b. bar c. TERM d. $TERM e. foo 31. If file foo contains the line x=123 then what is the bash output of this sequence of three commands: x=abc ; source foo ; echo "I see '$x' here." a. I see 'abc' here. b. "I see abc here." c. I see $x here. d. I see '$x' here. e. I see '123' here. 32. Which bash command sequence correctly searches for the string foobar and then prints YES if it is found inside the group file? a. if test foobar = /etc/group ; then echo YES ; fi b. if [ grep foobar /etc/group ] ; then echo YES ; fi c. if [ test foobar /etc/group ] ; then echo YES ; fi d. if grep foobar /etc/group ; then echo YES ; fi e. if test foobar /etc/group ; then echo YES ; fi 33. Which bash command line below allows programs in the current directory to execute without preceding the names with ./? a. PATH = ./$HOME:/bin b. PATH = /bin:$HOME:. c. $PATH=/bin:./$HOME d. $PATH=.:$HOME:/bin e. PATH=/bin:$HOME:. 34. If a bash shell script named foo contains the line: if [ '$1' = "$2" ] ; then echo SAME ; fi then which of the following command lines will produce SAME as output? a. ./foo $1 $1 b. ./foo 1 "$1" c. ./foo bar 'bar' d. ./foo bar '$1' e. ./foo 'bar' "bar" 35. A shell script named foo is executed as follows: ./foo 1 "2 3 4" 5 Inside the script is the line: argv.sh "$@" What is the count of arguments that the argv.sh command will display? a. 3 b. 4 c. 5 d. 1 e. 2 57 QuestionsDAT2330 Test #3 - Practice Unix Final - 0% 0 minutes DAT2330 - Ian Allen - Winter 20-7- 0 minutes 36. What is the output of the following sequence of bash commands: x=0 ; y=1 ; test ! -z $x ; echo $? a. no output b. test: $x: integer expression expected c. the number 1 or 0 followed by another 1 or 0 on a new line d. 1 e. 0 37. Which of the following shell command lines displays all the names in the current directory that are exactly three letters (alphabetic) long (and nothing else)? a. echo [0-89][01-9][0-45-9] b. echo ??? c. echo [a,zA,Z][a,zA,Z][a,zA,Z] d. echo [a-mn-zA-YZ][ab-zAB-YZ][za-yZA-Y] e. echo [azAZ][azAZ][azAZ] 38. A shell script named foo is executed as follows: ./foo 1 "2 2 2" '3 ' Inside the script is the line: argv.sh $@ What is the count of arguments that the argv.sh command will display? a. 3 b. 5 c. 2 d. 4 e. 6 39. What is the output of the following sequence of bash commands: echo hi >wc ; wc wc >hi ; cat hi a. no output b. hi c. 1 1 3 wc d. 0 0 0 wc e. 1 1 2 wc 40. Which bash command sequence below always outputs just the word OK only if the first argument is either a file or a directory? a. if [ "-f $1" || "-d $1" ]; then echo OK;fi b. if [ -f -o -d "$1" ]; then echo OK;fi c. if [ -f || -d "$1" ]; then echo OK;fi d. if [ "$1" -eq -f -o "$1" -eq -d ]; then echo OK;fi e. if [ -f "$1" -o -d "$1" ]; then echo OK;fi 41. A shell script named foo is executed as follows: ./foo 1 "2 3 4" 5 Inside the script is the line: echo "$2" What is the output from this line? a. "2 b. $2 c. 2 d. a bash error message: unbound (undefined) variable e. 2 3 4 57 QuestionsDAT2330 Test #3 - Practice Unix Final - 0% 0 minutes DAT2330 - Ian Allen - Winter 20-8- 0 minutes 42. Which line below is most likely to be the beginning of an error message? a. echo 2<$1 "... " b. echo 2>$1 "... " c. echo 1>&2 "... " d. echo 1<&2 "... " e. echo 2>&1 "... " 43. What is the output of the following sequence of bash commands: wc='one two' ; test wc = wc a. test: too many arguments b. 1 2 8 wc c. 1 d. 0 e. no output 44. If these two lines are put in an executable script named foo: #!/bin/cp bar echo hi What is the result of the command line: ./foo a. The file bar is copied to the file ./foo b. The cp command displays an error message about a missing argument c. The word "hi" appears on the screen d. The file ./foo is copied to the file bar e. The file bar appears on the screen followed by the word "hi" 45. What is the bash shell output of this two-command sequence if run in a directory containing 9999 files with names that are all the numbers from 1 to 9999 inclusive: x="*" ; echo '$x' a. the file names 1 through 9999, surrounded by quotes b. the file names 1 through 9999 c. * d. $x e. '$x' 46. If a=1 and b=2 then which of the following bash command lines outputs only the word hi (and nothing else)? a. [!a = b] && echo hi b. [ a -ne b ] && echo hi c. [ a = a ] && echo hi d. [a -ne b] || echo hi e. [a!=a] || echo hi 47. A shell script named foo is executed as follows: ./foo 1 "2 3 4" '5 ' Inside the script is the line: argv.sh "$@" What is the count of arguments that the argv.sh command will display? a. 4 b. 2 c. 5 d. 3 e. 6 57 QuestionsDAT2330 Test #3 - Practice Unix Final - 0% 0 minutes DAT2330 - Ian Allen - Winter 20-9- 0 minutes 48. If variable foo might contain nothing (a null value - defined but empty), which bash command sequence correctly tests for this and prints OK? a. if [ "$foo" = * ] ; then echo OK ; fi b. if [ ''$foo'' = '''' ] ; then echo OK ; fi c. if [ $foo -eq : ] ; then echo OK ; fi d. if [ $foo -eq "" ] ; then echo OK ; fi e. if [ "$foo" = "" ] ; then echo OK ; fi 49. In an empty directory, how many files will be created using the following bash shell two-command sequence: x='1 2 3 45' ; touch "$x" a. 5 files b. 2 files c. 4 files d. 1 file e. 3 files 50. What is the output of the following sequence of bash commands: false && echo "foo bar $?" a. foo bar 1 b. foo bar 0 c. no output d. foo bar 0 e. foo bar 1 51. In an empty directory, how many files will be created using the following bash shell two-command sequence: x="one 'two two'two three four" ; touch $x a. 3 files b. 1 file c. 4 files d. 5 files e. 2 files 52. What is the output of the following sequence of bash commands: a=cow ; b=dog ; test -z $a ; echo $? a. 0 b. test: $a: integer expression expected c. 1 d. the number 1 or 0 followed by another 1 or 0 on a new line e. no output 53. In an empty directory, what is the length of the longest file name created by the following bash shell two-command sequence: x='1 12 123 1234' ; touch '$x' a. 1 character b. 13 characters c. 3 characters d. 2 characters e. 4 characters 57 QuestionsDAT2330 Test #3 - Practice Unix Final - 0% 0 minutes DAT2330 - Ian Allen - Winter 20-10- 0 minutes 54. A shell script named foo is executed as follows: ./foo a b "c d e" Inside the script is the line: argv.sh "$*" What is the count of arguments that the argv.sh command will display? a. 5 b. 3 c. 4 d. 1 e. 2 55. What is the bash shell output of this two-command sequence if run in a directory containing 9999 files with names that are all the numbers from 1 to 9999 inclusive: x="*" ; echo $x a. * b. an asterisk ('*') and the file names 1 through 9999 c. $x d. the file names 1 through 9999 e. all the file names that start with an asterisk ('*') 56. How many arguments are passed to the command by the shell on this command line: bar bar bar a. 6 b. 3 c. 2 d. 5 e. 4 57. Which line below puts the count of the number of lines in the password file into the variable foo? a. foo=[ wc /etc/passwd | echo $1 ] b. foo=$( cat -c /etc/passwd ) c. foo=[ cat -l /etc/passwd ] d. foo=[ grep -c /etc/passwd ] e. foo=$( wc -l