6.2 Ifs and Lists Flashcards
Explain this if syntax:
if [ ]
then
fi
if -initiates our if statement.
[] - encapsulates the condition.
then - runs following commands if the condition is met.
fi - ends the if statement.
Explain this if syntax:
if [ 5 -gt 8 ]
then
echo “This doesn’t make sense!”
fi
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.
Explain this Else syntax:
if [ ]
then
else
fi
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.
Explain && syntax:
if [ ] &&; [ ]
then
fi
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.
Explain this || syntax:
if [ ] || [ ]
then
else
fi
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.
Explain this command:
output=$HOME/research/sys_info.txt
Create a variable to hold the path of your output file. sys_info.txt
A __________ is a temporary store for a piece of information. There are two actions we may perform for variables:
- 2.
A variable is a temporary store for a piece of information. There are two actions we may perform for variables:
- Setting a value for a variable
- Reading the value for a variable
Explain the following:
if [ ]
then
fi
Runs code if the condition is met.
Explain the following:
if [ ]
then
else
fi
Runs code if the condition is met. If condition isn’t met, it will run a different command.
Explain the following:
if [ ] && [ ]
then
fi
Runs code if more than one condition is met.
Explain the following:
if [ ] || [ ]
then
else
fi
Runs code if only one of multiple conditions are met.
Conditionals and Comparisons
=
This item is equal to another
Conditionals and Comparisons
==
If two items are equal.
Conditionals and Comparisons
!=
If two items are not equal
Conditionals and Comparisons
-gt
If one integer is greater than another.