First up some basics
WSL2 with ubuntu 20.04
A lot of the logic in the scripts I write rely on bash's
if.. then.. else. The basic syntax of the statement is as follows:
Why the square brackets?
[...] tells bash to evaluate the command and return 0 or 1 for the conditional expression inside the square brackets.
tldr; ensure things evaluate correctly.
Muting the output
> is used to redirect the output of a command somewhere.
Getting exit code from a command
$? returns the success of the previous command, 0 for success and >= 1 for failure. Lets look at the previous example and see what the output is.