0

What is the -n option in if statement in Linux?

Let's say there is a code:

if [ -n "$variable" ];then break;fi

What is it checking about the variable in if statement?

Biffen
  • 6,249
  • 6
  • 28
  • 36
Aviator
  • 543
  • 1
  • 4
  • 10

1 Answers1

1

-n checks if the corresponding string variable (in your case $variable) is of non-zero length.

kmalarski
  • 92
  • 9
  • that means if $variable has 0 length value then it will exit from if statement? – Aviator Oct 01 '21 at 08:59
  • If $variable has 0 length, nothing after "then" statement will be executed. You can easily see what happens by replacing break with an echo. – kmalarski Oct 01 '21 at 13:56