Conditional Expressions & Test Operators in Bash
Beginner · 30 minutes · 100 points
Master the fundamentals of conditional logic in Bash shell scripting. In this lab you will explore the test command, bracket expressions, and comparison operators to evaluate files, strings, and numbers. By the end you will be able to write reliable conditional checks that form the backbone of any shell script.
What you’ll learn
- Use the test command and [ ] / [[ ]] bracket expressions to evaluate conditions
- Apply file test operators (-f, -d, -e, -r, -w, -x) to check file and directory properties
- Compare strings and integers using appropriate test operators inside conditional statements
- Combine multiple conditions with logical AND (&&) and OR (||) operators in a script
How this lab works
- Start the lab: One click starts a container on your computer with a real terminal: nothing to install by hand, nothing to clean up.
- Work through 4 tasks: Each task says what to build or fix. You do it yourself, in a real terminal, with hints when you get stuck.
- Check your work: Check my work runs each task’s checks in your container and says what passed and what to fix.
- Finish and keep going: 100 points, your progress saved, and the next lab to try.
What it runs on
- Runs: A container on your computer, with a real terminal
- Image: ubuntu:22.04
What you need
- A free LearnXops account
- The LearnXops desktop app for macOS, Windows or Linux
- Docker Desktop installed and running
Topics: bash, shell-scripting, conditionals, test-operators, if-statements, linux
Create a free account to start this lab.