Chapter 11 Netacad Linux

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/17

encourage image

There's no tags or description

Looks like no tags are added yet.

18 Terms

1
New cards

A file begins with #!/bin/csh. This means:

a. This is a Perl script

b. The operator should not be using /bin/csh

c. C Shell compatibility mode is enabled

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

Nothing, this is a comment

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

2
New cards

Which are appropriate editors for writing shell scripts?(choose two)

Firefox

/bin/bash

LibreOffice Writer

vi

nano

vi

nano

3
New cards

Most of nano's commands take the form of:

Mouse clicks

Escape followed by another character

Control and another character

The F1 through F12 function keys

Alt and another character

Control and another character

4
New cards

What does this shell script do?

FOO=/tmp/foo

if [ ! -d $FOO ]; then

mkdir $FOO

fi

a. Creates /tmp/foo if it does not exist

b. Outputs a message to the screen

c. Creates /tmp/foo and raises an error if there is a problem

d. Nothing, since there is a problem with the conditions in the if statement

e. Makes the /tmp/foo directory if a file by that name exists

a. Creates /tmp/foo if it does not exist

5
New cards

Which of the following are correct about for and while loops?

(choose two)

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

b. for loops operate over a fixed list of items

c. for loops require a variable over which to iterate

d. while loops operate over a fixed list of items

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

b. for loops operate over a fixed list of items

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

6
New cards

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 parameter to -f, indicating the size of the file

It is the first argument passed to the script

It is a special variable that indicates the exit code of the command before it

It is a file called $1

It is a list of files that gets interpolated

It is the first argument passed to the script

7
New cards

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

If a file called "goodbye" exists in the current directory

8
New cards

What is the correct way to assign the word "Hello" to a variable?

A = "Hello"

echo "Hello" > A

echo A"Hello"</p><p>A "Hello"</p><p>A="Hello"

A="Hello"

A="Hello"

9
New cards

What is the correct way to save the current directory to a variable?

A=`pwd`

pwd | $A

A=cwd

A=pwd

pwd $A

A=`pwd`

10
New cards

Which shell command accepts input from the user's keyboard?

echo

read

gets

input

$1

read

11
New cards

What information is held inside $? ?

The name of the command run

The previous command's exit code

The number of arguments passed to the script

The current process id

The current user ID

The previous command's exit code

12
New cards

How would you finish your script with an exit code of 42?

return 42

break 42

CODE=42

exit 42

$?=42

exit 42

13
New cards

The if command looks for what exit code to consider a condition to be true?

1

0

2

10

255

0

14
New cards

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

test $USERS -eq 5

15
New cards

Given the following script:

while [ ! -f /tmp/foo ]; do

echo -n "."

process_data > /tmp/foo

done

Which of the following are true?

(choose two)

a. The screen will fill with dots.

b. If a file called /tmp/foo exists, process_data won't be run

c. process_data will be called at most once

d. process_data will never be run

e. /tmp/foo will be removed if it exists

b. If a file called /tmp/foo exists, process_data won't be run

c. process_data will be called at most once

16
New cards

A conditional that lets you make multiple comparisons with a pattern is called:

fanout

case

if

branch

test

case

17
New cards

What is the meaning of $(( $i + 1)) ?

1 will be added to the i variable

If i is 0, the loop will stop

This will return the value of the next argument to the script

This will return the value of the first argument to the script

This runs the command stored in variable i

1 will be added to the i variable

18
New cards

How would you write a test that says "if /tmp/foo is a directory or USERS is greater than 5"?

test -d /tmp/foo -o $USERS -gt 5

test -d /tmp/foo | $USERS > 5

test /tmp/foo || $USERS > 5

test /tmp/foo -d -o $USERS -gt 5

test -d /tmp/foo -o $USERS -gt 5