6.2 Ifs and Lists Flashcards

1
Q

Explain this if syntax:

if [ ]
then

fi

A

if -initiates our if statement.

[] - encapsulates the condition.

then - runs following commands if the condition is met.

fi - ends the if statement.

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

Explain this if syntax:

if [ 5 -gt 8 ]
then
echo “This doesn’t make sense!”
fi

A

if [ 5 -gt 8 ] - This will check to see if 5 is greater than 8.

then - Runs the following commands if the condition is met.

echo - “This doesn’t make sense!” Will have the script print to the screen “That
doesn’t make sense”.

fi - ends the if statement.

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

Explain this Else syntax:

if [ ]
then

else

fi

A

if [ ] - if this test is true…

then - runs the following code.

else - runs the following code if the condition is false.

fi - ends the if statement.

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

Explain && syntax:

if [ ] &&; [ ]
then

fi

A

if [ ] - checks if one condition is true.

&& - checks if a second condition is true.

Then - runs the following code if both conditions are met.

fi - ends the if statement.

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

Explain this || syntax:

if [ ] || [ ]
then

else

fi

A

if [ ] if condition 1 is true.

|| [] or if condition 2 is true.

then run the following code.

else runs code if both conditions are false.

fi ends the if statement.

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

Explain this command:

output=$HOME/research/sys_info.txt

A

Create a variable to hold the path of your output file. sys_info.txt

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

A __________ is a temporary store for a piece of information. There are two actions we may perform for variables:

  1. 2.
A

A variable is a temporary store for a piece of information. There are two actions we may perform for variables:

  1. Setting a value for a variable
  2. Reading the value for a variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Explain the following:

if [ ]

then

fi

A

Runs code if the condition is met.

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

Explain the following:

if [ ]

then

else

fi

A

Runs code if the condition is met. If condition isn’t met, it will run a different command.

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

Explain the following:

if [ ] && [ ]

then

fi

A

Runs code if more than one condition is met.

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

Explain the following:

if [ ] || [ ]

then

else

fi

A

Runs code if only one of multiple conditions are met.

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

Conditionals and Comparisons

=

A

This item is equal to another

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

Conditionals and Comparisons

==

A

If two items are equal.

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

Conditionals and Comparisons

!=

A

If two items are not equal

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

Conditionals and Comparisons

-gt

A

If one integer is greater than another.

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

Conditionals and Comparisons

-lt

A

If one integer is less than another.

17
Q

Conditionals and Comparisons

-d /path_to/directory

A

Checks for existence of a directory.

18
Q

Conditionals and Comparisons

-f /path_to?files

A

Checks for existence of a file.