Linux Tutorial Series

Linux Tutorial Series – 189 – Testing conditions

Here is the video version, if you prefer it:

In our script, we have tested if our first argument equals a certain string, that is:

[ "$1" = 'Hello' ]

there are other tests as well. You can test files (for example, if a file is a regular file), integers and strings. I won’t cover that here and will leave you this resource to look at if you want to learn more about these tests: (“Chapter 7. Tests,” n.d.)⁠ Relevant sections are 7.2 and 7.3.

But remember, no matter what test you are using, the gist of it is: “If this is true (if the exit code is 0) then do this, if not, do the other thing”.

Hope you learned something useful!


Chapter 7. Tests. (n.d.). Retrieved February 22, 2020, from Sections 7.2 and 7.3