Conditional Expressions Flashcards

Learn the different conditional expressions of the Bourne Again (bash) shell

1
Q

What is the result of this test? -a file

A

True if file exists

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

What is the result of this test? -b file

A

True if file exists and is a block special file.

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

What is the result of this test? -c file

A

True if file exists and is a character special file.

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

What is the result of this test? -d file

A

True if file exists and is a directory.

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

What is the result of this test? -e file

A

True if file exists.

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

What is the result of this test? -f file

A

True if file exists and is a regular file.

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

What is the result of this test? -g file

A

True if file exists and is set-group-id.

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

What is the result of this test? -h file

A

True if file exists and is a symbolic link.

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

What is the result of this test? -k file

A

True if file exists and its ``sticky’’ bit is set.

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

What is the result of this test? -p file

A

True if file exists and is a named pipe (FIFO).

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

What is the result of this test? -r file

A

True if file exists and is readable.

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

What is the result of this test? -s file

A

True if file exists and has a size greater than zero.

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

What is the result of this test? -t fd

A

True if file descriptor fd is open and refers to a terminal.

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

What is the result of this test? -u file

A

True if file exists and its set-user-id bit is set.

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

What is the result of this test? -w file

A

True if file exists and is writable.

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

What is the result of this test? -x file

A

True if file exists and is executable.

17
Q

What is the result of this test? -O file

A

True if file exists and is owned by the effective user id.

18
Q

What is the result of this test? -G file

A

|True if file exists and is owned by the effective group id.

19
Q

What is the result of this test? -L file

A

True if file exists and is a symbolic link.

20
Q

What is the result of this test? -S file

A

True if file exists and is a socket.

21
Q

What is the result of this test? -N file

A

True if file exists and has been modified since it was last read.

22
Q

What is the result of this test? file1 -nt file2

A

True if file1 is newer (according to modification date) than file2, or if file1 exists and file2 does not.

23
Q

What is the result of this test? file1 -ot file2

A

True if file1 is older than file2, or if file2 exists and file1 does not.

24
Q

What is the result of this test? file1 -ef file2

A

True if file1 and file2 refer to the same device and inode numbers.

25
Q

What is the result of this test? -o optname

A

True if shell option optname is enabled.

26
Q

What is the result of this test? -z string

A

True if the length of string is zero.

27
Q

What is the result of this test? string -n string

A

True if the length of string is non-zero.

28
Q

What is the result of this test? string1 == string2 string1 = string2

A

True if the strings are equal.

29
Q

What is the result of this test? string1 != string2

A

True if the strings are not equal.

30
Q

What is the result of this test? string1 < string2

A

True if string1 sorts before string2 lexicographically.

31
Q

What is the result of this test? string1 > string2

A

True if string1 sorts after string2 lexicographically.

32
Q

What is the result of this test? arg1 OP arg2 OP is one of -eq, -ne, -lt, -le, -gt, or -ge.

A

true if arg1 is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to arg2, respectively. Arg1 and arg2 may be positive or negative integers.