Bash memo for (if statement and test command)

Maciej
2 min readAug 8, 2022
Photo by Waldemar Brandt on Unsplash

Prerequisite knowledge

  • The if statement determines the exit status of the command specified in the conditional expression and branches. True if the exit status is 0, false otherwise
  • [ "A" = "A"] If there is no space between [] like this, an error will occur. For example ["A" = "A"], it is an error to write. It is easy to understand if [ is a command
  • <,>,<=,>= cannot be used in conditional expressions. You can use -lt(<),-gt(>),-le(<=),-ge(>=) instead. -lt (less than), -gt (greater than), -le (less than or equal), -ge (greater than or equal), respectively. But it’s hard to understand, so I wrote it all down.
  • If you have any trouble , just use man

Command collection

All you can find in this repo

  1. Are the strings equal?
  2. Use > as a conditional expression → Use -gt (greater than)
  3. Use < in a conditional expression → Use -lt (less than)
  4. Use >= in a

--

--

Maciej
Maciej

Written by Maciej

DevOps Consultant. I’m strongly focused on automation, security, and reliability.

No responses yet