Chapter 19. An Introduction to Bash Shell Scripting Flashcards

1
Q

What is the effect if a script does not start with a shebang?

A

The script will be interpreted by the same shell as the parent shell.

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

How can you check if a variable VAR has no value?

A

test -z $VAR or [ -z $VAR ] can be used to check whether a variable VAR has no value.

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

What would you use in a script to count the number of arguments that have been used?

A

Use $# to count the number of arguments that have been used.

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

What would you use to refer to all arguments that have been used when starting the script?

A

Use $@ to refer to all arguments that have been used when starting the script.

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

How do you process user input in a script?

A

Use “read SOMEVAR” to process user input in a script.

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

What is the simplest way to test whether a file exists and execute the command echo “file does not exist” if it does not?

A

”[ -f filename ] || echo file does not exist” determines whether the file exists and, if not, executes the specified command.

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

Which test would you perform to find out if an item is a file or a directory?

A

[ -e filename ] can be used to determine whether an item is a file or a directory.

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

Which construction would you use to evaluate a range of items?

A

A for statement is typically used to evaluate a range of items.

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

How do you close an elif statement in a script?

A

You do not; it is a part of the if statement that is closed with fi.

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

In a case statement, you evaluate a range of items. For each of these items you execute one or more commands. What do you need to use after the last command to close the specific item?

A

Using ;; after the last command closes the specific item.

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