CH11 Flashcards

1
Q

A File begins with #!/bin/csh. This means?

This is a Perl script
The operator should not be using /bin/csh
C Shell compatibility mode is enabled
Running the script will invoke /bin/csh to interpret the rest of the file
Nothing, this is a comment

A

Running the script will invoke /bin/csh to interpret the rest of the file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
2. What does this shell script do?
FOO=/tmp/foo
if [ ! –d $FOO ]; then
    mkdir $FOO
fi

Creates /tmp/foo if it does not exist
Outputs a message to the screen
Creates /tmp/foo and raises an error if there is a problem
Nothing, since there is a problem with the conditions in the if statement
Makes the /tmp/foo directory if a file by that name exists

A

Creates /tmp/foo if it does not exist

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. Which of the following are correct about for and while loops? (Choose Two)

for loops have a test each cycle to determine if it should run again
for loops operate over a fixed list of items
for loops require a variable over which to iterate
while loops operate over a fixed list of items
while loops have a test each cycle to determine if it should run again

A

for loops operate over a fixed list of items

while loops have a test each cycle to determine if it should run again

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
4. Given the following script that is run through ./test.sh hello goodbye:
if [ -f $2 ]; then
    echo "I am here"
fi
When will “I am here” be printed?

If a file called “goodbye” exists in the current directory
Never
The script will always print “I am here”
If there are two files in the current directory
If a file called “hello” exists in the current directory

A

If a file called “goodbye” exists in the current directory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. What is the correct way to assign the word “Hello” to a variable?
A = “Hello”
echo “Hello” > A
echo $A “Hello”
$A=”Hello”
A=”Hello”
A

A=”Hello”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. What is the correct way to save the current directory to a variable?
A=`pwd`
pwd | $A
A=cwd
A=pwd
pwd $A
A

A=pwd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. Which shell command accepts input from the user’s keyboard?
echo
read
gets
input
$1
A

read

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. How would you finish your script with an exit code of 42?
return 42
break 42
CODE=42
exit 42
$?=42
A

exit 42

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. The if command looks for what exit code to consider a condition to be true?
1
0
2
10
255
A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. The number of users logged in is in a variable called USERS. How would you test to see if 5 users are logged in?
test $USERS –eq 5
test –f USERS=5
test $USERS = 5
test $USERS,5
test $USERS –a 5
A

test $USERS –eq 5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly