If Then Comparisons Flashcards

1
Q

-eq

A

equal to (for numbers)

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

[[ STRING == STRING ]]

A

equal to (for strings)

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

-ne

A

not equal to (for numbers)

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

[[ STRING != STRING ]]

A

not equal to (for strings)

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

-lt

A

less than (for numbers)

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

-le

A

less than or equal to (for numbers)

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

-gt

A

greater than (for numbers)

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

-ge

A

greater then or equal to (for numbers)

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

Write an
if statement

include the additional syntax options.

A
if commands; then
    commands

[elif commands; then 
    commands...]

[else 
    commands]
fi
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Special variables:
$?

A

Exit status of
last task:
0-255

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

Special variables:
$!

A

PID of last background task

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

Special variables:
$$

A

PID of shell

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

Special variables:
$0

A

Filename of the shell script

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

Special variables:
$_

A

Last argument of the previous command

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

Special variables:
${PIPESTATUS[n]}

A

return value of
piped commands
(array)

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

Exit status 0

A

0 indicates success

17
Q

Exit status 1

A

Any exit status other than 0 means failure

18
Q

[[ -z STRING ]]

A

empty string, true

19
Q

[[ -n STRING ]]

A

not empty string, true

20
Q

[[ STRING =~ REGEX ]]

A

Compares String against a Regexp (for strings)

Example:
LINE=”Spaces Present”
NOLINE=”SpacesNotPresent”
if [[ “${NOLINE}” =~ [[:space:]] ]]; then
echo “true for ${NOLINE}”
#echo “Line Number: ${LINENO}”
else
echo “false for ${NOLINE}”
fi

This will print for $LINE but false for $NOLINE

21
Q

(( NUM < NUM2 ))

A

Evaluating numerical conditions, specifically NUM2 is greater than NUM, then TRUE

22
Q

What is clobbering in bash shell?

A

The process of overwriting existing data [files].

23
Q

What is noclobber in bash shell?

A

A setting that will make the shell complain if a redirect is trying to overwrite an existing file.

24
Q

How do you enable noclobber?

A

$ set -o noclobber

to check the setting:
$ set -o | grep clobber

25
How do you disable noclobber?
$ set +o noclobber
26
[[ -o noclobber ]]
If OPTIONNAME is enabled. Example is noclobber.
27
[[ ! EXPR ]]
Not
28
[[ X && Y ]]
And
29
[[ X || Y ]]
Or
30
Bash Options: $ set -o noclobber
Avoid overwriting files (echo "hi" > foo)
31
Bash Options: $ set -o errexit
Used to exit upon error, avoiding cascading errors
32
Bash Options: $ set -o pipefail
Unveils hidden failures
33
Bash Options: $ set -o nounset
Exposes unset variables