EasyEnv
Engineering/Courses/Catalog/Bash/Conditionals and Tests
Bash
BeginnerLesson 4 of 1230 min · hands-on

Conditionals and Tests

Part of the Bash course

Every script you have written so far runs the same lines no matter what. Real scripts need to make decisions: "only do this if that file exists", "only continue if the last command worked". This lesson teaches you how Bash asks those questions and acts on the answer. Nothing here assumes you have written a decision-making program before.

In lesson 02 you met the exit code: a hidden number every command produces when it finishes, where 0 means success and anything else means failure. Conditionals in Bash are built entirely on that idea. Where other languages ask "is this true or false?", Bash asks "did this command succeed or fail?" and treats success as yes: if does not look at a value, it runs a command and reacts to whether its exit code was 0. ...

Want to learn Bash Conditionals and Tests in a real environment?

Click below, get a fresh Linux box with Bash ready to go, and work through Conditionals and Tests hands-on with an AI tutor that knows your code.

Start this lessonConditionals and Tests

What you'll learn

  • If statement
  • [[ ]] tests
  • String tests
  • File tests -f -d -e
  • && and ||
  • Case statement

Read this lesson in your language

All lessons in this course

12 lessons
  1. 1What Is Bash20 min
  2. 2Shebang and Your First Script25 min
  3. 3Variables and Quoting25 min
  4. 4Conditionals and Tests30 min
  5. 5Loops25 min
  6. 6Functions25 min
  7. 7Arrays25 min
  8. 8String and Arithmetic Expansion25 min
  9. 9IO Redirection and Pipes25 min
  10. 10Error Handling and Traps30 min
  11. 11Debugging and Best Practices25 min
  12. 12Capstone: Server Bootstrap Script60 min

Explore other courses

Conditionals and Tests - Bash (English) | Engineering Courses