ScriptingLesson 49Free preview
Bash If...Else
This lesson is part of Bash · All levels
Summary
The if branch checks a condition and then executes the command block accordingly. The structure begins with if, continues then, optional else or elliptic, and closes with fi. Conditions are generally written in square brackets that must be given spaces within parentheses.
Key points
- Structure: if [condition]; then...; else...; fi
- Space in square brackets must be there.
- [[]] a more secure version of Bash for string
- The ellipse replaces the otherwise-if repeated
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.