bash - Can I omit the then part in an if statement? -


how correct bash syntax this:

if [ "$actual" == "$expected" ];    donothing else    echo "error: actual: $actual. expected: $expected" fi 

i looking works possible values of variables "actual" , "expected". content of variables must not interpreted/evaluated/expanded in way. script not need portable (a bash solution ok).

you use simplest do-nothing statement available:

if [ "$actual" = "$expected" ];    : else    echo "error: actual: $actual. expected: $expected" fi 

(note: 1 = not 2 in [/test.)

but better idea invert test , remove need entirely:

if [ "$actual" != "$expected" ];   echo "error: actual: $actual. expected: $expected" fi 

Comments