Upwork Test Answers: Get all the correct answers of most recent and possible Upwork Tests A to Z (Updated on Jan, 2016)
Cover Letter Templates: These cover letter samples are not only for Upwork job, but also you will have some idea about your real life job
 
Freelance Profile Overviews: Different Profile samples and overviews of experts, advanced and intermediate level freelancers
For Newbie of Upwork: Upwork Help - How to apply for a job in Upwork with 10 most important articles about Upwork

A to Z View - All Upwork Test Answers

Unix Shell Script Test Answers (new)

This post will help you to get Upwork Unix Operating System related job. If you want your Upwork profile looks better then others, just check out this test answers. Here you will find most recent Upwork test questions with updated answers of Upwork Unix Shell Script Test for Operating Systems category.

Please press Ctrl + F to find your desired answers of the test questions.
--------------------------------------------------------------------------------------------------------------------------
1. Which of the following is/are allowed in an arithmetic statement involving expr command?
 Answers: • ( ) or • %

 2. A shell variable cannot start with:
 Answers: • A number and a special symbol other than the underscore

 3. What is the error in the following shell script code?

 1. until=1
 2. while [ $until -eq 5 ]
 3. do
 4. echo until cannot be used as a variable name
 5. until=`expr $until + 1`
 6. done
 Answers: • There is no error

 4. What is the output of the following program?

 b=
 [ -n $b ]
 echo $?
 [ -z $b ]
 echo $?
 Answers: • 0 0

 5. What is the output of the following program?

 a=300
 [ -n $a ]
 echo $?
 [ -z $a ]
 echo $?
 Answers: • 0 1

 6. What is the error in the following program?

 1. x=10
 2. if [ x -ge 2 ]
 3. then
 4. echo $x
 5. fi
 Answers: • Line 2 should be if [ $x -ge 2 ]

 7. Which of the following is true about "until" loop?
 Answers: • It is executed as long as the given condition or list of items evaluate to true.

 8. If x=11 and y=6, then what is the exit status of the following expression?

 [ ! $x -gt 9 -a ! $y -ne 23 ]
 Answers: • 0

 9. What is the output of the following program?

 x=3
 y='[$x -eq 10 ]'
 z='[$x -lt 10 ]'
 echo x=$x y=$y z=$z
 Answers: • None of the above

 10. Which of the following statements is false?
 Answers: • Programs written for Bourne shell are compatible with Korn shell.

 11. What is the output of the following shell script code?

 suite=3
 case $suite in
 1) echo Diamond ;;
 2) echo Spade ;;
 3) echo Heart ;;
 4) echo Club ;;
 esac
 Answers: • Heart

 12. What would be the condition to check whether file with name "xyz" is a regular file?
 Answers: • if [ -f xyz ]

 13. Which of the following statements is incorrect regarding if-then-fi?
 Answers: • The indentation is mandatory otherwise an error will occur on execution.

 14. If x=11 and y=6, then what is the exit status of the following expression?

 [ $x -eq 11 -a $y -ne 89 ]
 Answers: • 0

 15. Which of the following expressions is correct?
 Answers: • a=`expr $b \* \( $c + $d \ )`

 16. What will be the output of the following program assuming that the command line arguments are dog parrot cuckoo?

 for argument in "$*"
 do
 echo $argument
 done
 Answers: • dog parrot cuckoo

 17. Which of the following is true about the "continue" statement?
 Answers: • It continues the control to the beginning of the loop, bypassing the statements below it, inside the loop.

 18. Which of the following lines have an error?

 1. echo enter your name
 2. read filename
 3. read name < $filename
 4. echo $name
 Answers: • There is no error.

 19. What is the error in the following program?

 1. while who | grep aa12 | wc -l
 2. do
 3. echo false
 4. done
 Answers: • There is no error

 20. Which of the following assignments is illegal?
 Answers: • d = 25

 21. What is the output of the following program?

 i=1
 for [ i -le 10 ]
 do
 echo $i
 i='expr $i + 1'
 done
 Answers: • An error will occur

 22. The break statement is used to exit from:
 Answers: • a "for" loop.

 23. What is the error in the following program?

 1. j=10 k=12
 2. if [ $k>=$j ]
 3. then
 4. k=$j
 5. j=$k
 6. fi
 7. echo $j $k
 Answers: • There is no error

 24. Precedence hierarchy decides which operator:
 Answers: • is used first.

 25. What is the output of the following program?

 i=1 j=1 k=1
 while [ $i -lt 10 ]
 do
 while [ $j -lt 10 ]
 do
 while [ $k -lt 10 ]
 do
 echo $i $j $k
 k='expr $k + 1'
 break 3
 done
 j='expr $j + 1'
 done
 i='expr $i + 1'
 done
 Answers: • 1 1 1

 26. The exit statement is used in a loop to:
 Answers: • terminate the execution of a script.

 27. The expression expr -7 % 2 evaluates to:
 Answers: • -1

 28. What is the error in the following shell script code?

 #!/bin/sh
 1. a=12.25 b=12.52
 2. if [a=b]
 3. then
 4. echo "\na and b are equal"
 5. fi
 Answers: • On line 2, [a=b] should be replaced with [ $a -eq $b ]

 29. What is the output of the following program?

 for i in 'a b c d e'
 do
 echo $i
 done
 Answers: • a b c d e

 30. What is the output of the following program?

 i=4 z=12
 [ $i = 5 -a $z -gt 5 ]
 echo $?
 Answers: • 1

 31. What is the output of the following program?

 terminal=vt100
 case $terminal in
 vt100) echo Dec terminal;;
 vt200) echo Old terminal;;
 ansi) echo Commonly used terminal;;
 v*) echo vt series terminal;;
 *) echo Any terminal;;
 esac
 Answers: • Dec terminal

 32. Which of the following is not a shell keyword?
 Answers: • ls

 33. What is the error in the following loop statement?

 while [ $1 -gt 10 -a \($2 -o -w $3 \) ]
 Answers: • There is no error

 34. The statement z=`expr 5 / 2` would store which of the following values in z?
 Answers: • 2

 35. The expression expr -2 % 7 evaluates to:
 Answers: • -2

 36. Which of the following variable names is invalid?
 Answers: • #regpay

 37. Which of the following assignments is illegal?
 Answers: • c=`1972`

 38. On executing the statement:

 set -3 + 1
 Answers: • An error would occur

 39. Which of the following statements is true?
 Answers: • There is no restriction on the length of a shell variable name.

 40. A shell script is executed by:
 Answers: • an interpreter.

 41. Which of the following is/are correct declaration(s) of a null variable "a" in shell script?
 Answers: • a=

 42. What is the error in the following program?

 1. j=1
 2. while [ $j -le 10 ]
 3. do
 4. echo $j
 5. j = j + 1
 6. done
 Answers: • Line 5 should be j=`expr $j + 1`

 43. What will be the output of the following program assuming that the command line arguments are dog parrot cuckoo?

 for argument in $*
 do
 echo $argument
 done
 Answers: • dog parrot cuckoo

 44. What is the output of the following program?

 for i in a b c d e
 do
 echo $i
 done
 Answers: • a b c d e

 45. What will be the output of the following program assuming that the command line arguments are Unix shell scripting?

 for argument in *
 do
 echo $argument
 done
 Answers: • The names of all files in the current directory would be displayed

 46. What is the error in the following program?

 1. j=10 k=12
 2. if test [ $k -ge $j ]
 3. then
 4. k=$j
 5. j=$k
 6. fi
 7. echo $j $k
 Answers: • Output will be 10 12 with a warning message in line 2

 47. Which of the following loops is invalid?
 Answers: • while $

 48. Suppose you are writing a shell script that accepts five positional parameters from the terminal. What will be the effect of using statement "shift 1" in your shell script and then executing the shell script?
 Answers: • The positional parameters would be shifted by one position towards left i.e. parameter 1 will have value of parameter 2, parameter 2 will have value of parameter 3 and so on.

 49. What is the output of the following program?

 1. x=3 y=5 z=10
 2. if [ \($x -eq 3\) -a \( $y -eq 5 -o $z -eq 10 \) ]
 3. then
 4. echo $x
 5. else
 6. echo $y
 7. fi
 Answers: • 5 and a warning about line 2 will occur

 50. What is the output of the following program when directory name "home" is given as input?

 echo Enter a directory Name
 read dirname
 case $dirname in
 *) echo any directory name ;;
 c*) echo cobol directory name ;;
 f*) echo fortran directory name ;;
 p*) echo pascal directory name ;;
 esac
 Answers: • any directory name

 51. What is the output of the following program?

 k=35
 echo `[ $k -eq 35 ]``[ $k -eq 50 ]`
 Answers: • A blank line will result

 52. Which of the following expressions is valid?
 Answers: • tput cup $row $col

 53. Suppose there are three files test0.sh, test1.sh, and test2.sh in your current directory. Which of the following options would occur during the execution of read statement?

 exec < test0.sh
 exec < test2.sh
 exec < test3.sh
 read line
 echo $line
 Answers: • It would read only test3.sh