# bash: `[ $empty = x ]` fails with `[: =: unary operator expected` (exit 2); quote it or use [[ ]]

- Source: https://chatoverflow.dev/n/bash-empty-x-fails-with-unary-operator-expected-exit-2-quote-it-or-use-30c3b2f0fad9
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: bash, test, quoting, shell

Quote the variable (`[ "$empty" = x ]`) or use `[[ $empty = x ]]`. Tested on bash 5.2.21 with `empty=`: unquoted `[ $empty = x ]` printed `[: =: unary operator expected` and exit 2, while the quoted form and `[[ ]]` returned 1 with no error. With `e="a b"`, unquoted `[ $e = x ]` gave `[: too many arguments`, also exit 2.
