CS211 Shell Programming

Review for Third Quiz

  1. The proper format for an if structure might be
    1.  if-then-else-if-elif
    2.  if-then-elif-then-else-fi
    3.  if-elif-then-else-endif
    4.  fee-fi-fo-fum-if-else-look-dumb


  2. The exit status of a command will be
    1.  equal to 1 if successful
    2.  equal to 0 if successful
    3.  equal to some positive number if successful
    4.  a number based on the command itself


  3. An exit status can be read with
    1.  ?#
    2.  ?*
    3.  $?
    4.  $*


  4. A test condition for integers can be written as
    1.  [var1 <= var2]
    2.  [ var <= var2 ]
    3.  [ var1 le var2 ]
    4.  [ var1 -le var2 ]


  5. Test conditions for strings use other operators:
    1.  =, !=, -n, -z
    2.  isstring, isint, isalpha
    3.  No, they use the same operators as integers.
    4.  Operators are not used with strings.


  6. To test if a file exists in $HOME, you can use
    1.  [ f filename $HOME ]
    2.  [ -f filename $HOME ]
    3.  [ -f /$HOME/filename ]
    4.  [ -f $HOME/filename ]


  7. The case statement is most useful
    1. when there is only one possible branch
    2. when there are two alternative branches
    3. when there are multiple possible branches
    4. when there are no possible branches


  8. To link two possible user responses with an OR in a case
    1.  T OR t)
    2.  "T" or "t")
    3.  "T"|"t")
    4.  "T") | "t")


  9. A for loop in a script does not require
    1.  for
    2.  do
    3.  done
    4.  until


  10. A for loop is not useful
    1.  when the user chooses a number of times to loop
    2.  when the user enters a list to process
    3.  when the loop processes all files in a directory
    4.  when expanding wildcards to make a list


  11. The continue statement means
    1.  quit the loop and go on
    2.  quit this iteration and start the next
    3.  quit the program
    4.  quit this: go get a life


  12. The break statement means
    1.  quit the loop and go on
    2.  quit this iteration and start the next
    3.  quit the program
    4.  I told you: go get a life


  13. The while loop
    1.  can run any number of times
    2.  does not require a test condition
    3.  runs once for each item in a list
    4.  cannot be made into an infinite loop


  14. The until command
    1.  is totally unlike a loop
    2.  requires no test condition
    3.  processes a list of items
    4.  runs until its condition becomes true


  15. Creating a menu for a user helps because
    1.  user's are dumb and need help
    2.  it avoids the user having to enter a complex command
    3.  computers won't function with menus
    4.  menus slow things down


  16. Which phrase will give var1 the value of 7 if it is not already defined?
    1.  ${var1/7}
    2.  ${var1}
    3.  ${var1:="7"}
    4.  ${var1?0:7}


  17. To invoke another program in a case statement use
    1.  program ;;
    2.  invoke program ;;
    3.  run program ;;
    4.  attn computer: run program


  18. When a second program you start inside a script stops running
    1.  the script stops running, too
    2.  you drop to a command line for help
    3.  control flows to the next line in the script
    4.  control flows to the lowest point


  19. To view the contents of a file on screen, any of these might work, except
    1.  ls filename
    2.  cat filename
    3.  more filename
    4.  $MORE filename


  20. Sorting a file with fields is possible. Which command means to sort only on the 4th and 5th fields:
    1.  sort +4 -5 filename
    2.  sort +3 -5 filename
    3.  sort on 4:5 filename
    4.  sort filename 4-5


  21. Sorting a file in descending order is easy:
    1.  sort -d file
    2.  sort -v file
    3.  sort -r file
    4.  sort -b file