Unix Review
Unix Review
Scripts
First line
How to see the success/failure exit code from the previous line in a script.
Exit ??
What exit code is returned from a script by default
Status of last command
How to return a specific exit code from a script
Exit number
How to check the exit code immediately after a script has run
Permissions and execution
Variables
How to assign the output of a command to a variable
Name=$()
How to append the value of a variable to an existing variable (PATH example in
homework 4)
trade PATH=$PATH:/home/joe:/home/joe/container
path=$secondpath
Command redirection
How would you use a redirection operator to pass the contents of a file into a
command?
>>
How would you redirect the error output of a command so that it goes to a file?
How would your redirect the error and standard outputs of a command to different
files?
Err.txt
How would your redirect the error and standard outputs of a command to different
files?
How do you throw away everything output by a command?
How do you redirect the output of a command to several files?
How would you use process redirection (process substitution) to redirect the output of
a series of commands to a while loop?
Conditional statements
file1=filename
string1=hello
string2=
string3=goodbye
num1=1
num2=200
if condition ; then
fi
Condition expressions:
Given the pseudo-code above, write the condition expressions to test for these states:
(Include the appropriate brackets or parentheses.)
file1 is a directory
if[[ -d file1 ]]
file1 exists
if [[ -e file1 ]]
file1 is not empty
if [[ -I file1 ]]
string1 equals string2
if [[ string1 -eq string2 ]]
string1 comes before string1
if [[
string2 is empty
if [[ -z strigng2 ]]
string3 is not empty
string [[ -n string3 ]]
num1 is greater than num2
if (( num1 > num2 ))
num1 is not zero
if (( num1 != 0 ))
if-free conditionals.
Repeat the tests above using if-free conditionals using && or ||
Control structures.
Give the keywords, punctation, and layout of these structures
while-loop
For-loops.
Write for-loops that cycle through:
all the files in a directory
all the numbers between 10 and 15
all the even numbers between 8 and 20
the list of names Alfie Brando Charlie Della Eka
all the lines in a file
While-loops
Write a while loop that reads its input line by line from a file
Write a while loop that reads its input field by field from a file
Write a while loop that reads its input line by line from a here-document
Write a while loop that redirects its output to a file
Write a for loop that re-directs its output to a file
Write a while loop reads its input from stdin
grep
What should you never do with ls and grep?
Put them together
CS2080-002 Programming with Unix Page 4
Review 2
How to use a file glob/wildcard pattern when telling grep what files to search.
How to put multiple glob patterns in the same grep command line
What are the grep options for:
ACL's
How do you read and set access control lists?