Learning resources

Official documentation




Quoting in Bash

Globbing in Bash

Filename expansion is called "globbing"

Unary operator expected

A unary operator only has one argument. A binary operator has two arguments.

For example, -eq is a binary operator, because it has two arguments and figures out whether they're equal.

When the shell sees [ 3 -eq 3 ], everything is fine, because -eq takes two arguments, and it has been given two arguments, the 3s. What if one of those was blank, though? It would be either [ -eq 3 ] or [ 3 -eq ]. Those are missing one of the arguments, so the shell gets to thinking you meant to use an operator that only has one argument, a unary operator.

Your variables can be blank, causing just this problem. To avoid the issue, surround all uses of a variable with double quotes.

Solutions to common problems

Building my own library with my user-defined functions

Handling command line arguments

Using colors in Bash

Strings manipulation


Bash cheatsheet

Back to top