mora
mora

Reputation: 2287

Is [[ ${variable} ]] same as [[ -n ${variable} ]] in bash?

I read a code which is written by another person in bash. It includes the following code,

[[ ${variable} ]]

It seems it works as

[[ -n ${variable} ]]

Is it correct?

Upvotes: 2

Views: 85

Answers (1)

heemayl
heemayl

Reputation: 42087

Yes, without any option inside [[ ([[ is a bash keyword though), the behavior is exactly same to using the -n option i.e. it is checking if the string is non-empty (i.e. length > 0), and gives exit status 0 if the string is not empty as you can imagine.

Upvotes: 3

Related Questions