ceving
ceving

Reputation: 23876

Which `[` can not compare empty strings?

In some ancient Shell scripts for Solaris I found the following notation to check if a variable is empty:

[ x"$var" = x ]

On a current Linux system I would write it just as

[ "$var" = "" ]

or

[ -z "$var" ]

Which version of [ actually requires the first notation?

Upvotes: 1

Views: 279

Answers (1)

Dunatotatos
Dunatotatos

Reputation: 1746

None.The alias from [] to test appears after the option -z of test. Therefore, if you can use [ x"$var" = x], you can also write [ -z "$var" ].

Upvotes: 1

Related Questions