|
|
CS211 Shell Programming
Review for Third Quiz
- The proper format for an if structure might be
- if-then-else-if-elif
- if-then-elif-then-else-fi
- if-elif-then-else-endif
- fee-fi-fo-fum-if-else-look-dumb
- The exit status of a command will be
- equal to 1 if successful
- equal to 0 if successful
- equal to some positive number if successful
- a number based on the command itself
- An exit status can be read with
- ?#
- ?*
- $?
- $*
- A test condition for integers can be written as
- [var1 <= var2]
- [ var <= var2 ]
- [ var1 le var2 ]
- [ var1 -le var2 ]
- Test conditions for strings use other operators:
- =, !=, -n, -z
- isstring, isint, isalpha
- No, they use the same operators as integers.
- Operators are not used with strings.
- To test if a file exists in $HOME, you can use
- [ f filename $HOME ]
- [ -f filename $HOME ]
- [ -f /$HOME/filename ]
- [ -f $HOME/filename ]
- The case statement is most useful
- when there is only one possible branch
- when there are two alternative branches
- when there are multiple possible branches
- when there are no possible branches
- To link two possible user responses with an OR in a case
- T OR t)
- "T" or "t")
- "T"|"t")
- "T") | "t")
- A for loop in a script does not require
- for
- do
- done
- until
- A for loop is not useful
- when the user chooses a number of times to loop
- when the user enters a list to process
- when the loop processes all files in a directory
- when expanding wildcards to make a list
- The continue statement means
- quit the loop and go on
- quit this iteration and start the next
- quit the program
- quit this: go get a life
- The break statement means
- quit the loop and go on
- quit this iteration and start the next
- quit the program
- I told you: go get a life
- The while loop
- can run any number of times
- does not require a test condition
- runs once for each item in a list
- cannot be made into an infinite loop
- The until command
- is totally unlike a loop
- requires no test condition
- processes a list of items
- runs until its condition becomes true
- Creating a menu for a user helps because
- user's are dumb and need help
- it avoids the user having to enter a complex command
- computers won't function with menus
- menus slow things down
- Which phrase will give var1 the value of 7 if it is not already defined?
- ${var1/7}
- ${var1}
- ${var1:="7"}
- ${var1?0:7}
- To invoke another program in a case statement use
- program ;;
- invoke program ;;
- run program ;;
- attn computer: run program
- When a second program you start inside a script stops running
- the script stops running, too
- you drop to a command line for help
- control flows to the next line in the script
- control flows to the lowest point
- To view the contents of a file on screen, any of these might work,
except
- ls filename
- cat filename
- more filename
- $MORE filename
- Sorting a file with fields is possible. Which command means to sort
only on the 4th and 5th fields:
- sort +4 -5 filename
- sort +3 -5 filename
- sort on 4:5 filename
- sort filename 4-5
- Sorting a file in descending order is easy:
- sort -d file
- sort -v file
- sort -r file
- sort -b file
|