Hoofdstuk 9 meerkeuze Flashcards
The echo command:
Is used for variable assignment Duplicates the input stream to the output stream Is used to output text to the console Tests a variable for duplication Copies variables from one to another
Is used to output text to the console
A file begins with #!/bin/csh. This means:
Nothing, this is a comment C Shell compatibility mode is enabled The operator should not be using /bin/csh Running the script will invoke /bin/csh to interpret the rest of the file This is a Perl script
Running the script will invoke /bin/csh to interpret the rest of the file
Which are appropriate editors for writing shell scripts?
(choose two)
/bin/bash vi LibreOffice Writer Firefox nano
vi
nano
Most of nano’s commands take the form of:
Control and another character Alt and another character Mouse clicks The F1 through F12 function keys Escape followed by another character
Control and another character
What does this shell script do? FOO=/tmp/foo if [ ! –d $FOO ]; then mkdir $FOO fi
Creates /tmp/foo if it does not exist Makes the /tmp/foo directory if a file by that name exists 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
Creates /tmp/foo if it does not exist
Which of the following are correct about for and while loops?
(choose two)
for loops operate over a fixed list of items while loops operate over a fix list of items for loops have a test each cycle to determine if it should run again while loops have a test each cycle to determine if it should run again for loops require a variable over which to iterate
for loops operate over a fixed list of items
while loops have a test each cycle to determine if it should run again
Given the following part of a script:
if [ -f $1 ]; then
echo “I am here”
fi
What is the meaning of $1? It is a special variable that indicates the exit code of the command before it It is the first argument passed to the script It is a file called $1 It is a parameter to –f, indicating the size of the file It is a list of files that gets interpolated
It is the first argument passed to the script
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 there are two files in the current directory The script will always print “I am here” Never If a file called “hello” exists in the current directory If a file called “goodbye” exists in the current directory
If a file called “goodbye” exists in the current directory
What is the correct way to assign the word “Hello” to a variable?
$A=”Hello” echo “Hello” > A A=”Hello” echo $A “Hello” A = “Hello”
A=”Hello”
What is the correct way to save the current directory to a variable?
A=`pwd` A=pwd A=cwd pwd $A pwd | $A
A=pwd
Which shell command accepts input from the user’s keyboard?
echo $1 read input gets
read
What information is held inside $? ?
The current process id The number of arguments passed to the script The current user ID The previous command’s exit code The name of the command run
The previous command’s exit code
How would you finish your script with an exit code of 42?
return 42 $?=42 CODE=42 exit 42 break 42
exit 42
The if command looks for what exit code to consider a condition to be true?
10 255 0 1 8
0
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 –f USERS=5 test $USERS = 5 test $USERS,5 test $USERS –eq 5 test $USERS –a 5
test $USERS –eq 5