KornShell Logical Conditional Logic

I am a little confused by this KornShell (ksh) script. I write mainly with boolean and conditional expressions.

So, the first part of my script I have catmeand wcmethat are installed both on trueand on false. This part works fine since I tried them echoand they give the expected results. Later I have this code:

if [[ $catme ]] ; then
    some commands
fi

And I repeat this with wcme. Surprisingly, however, no matter what wcme, and catme, the team inside my operator ifperformed.

Is this a syntax error? I tried [[ $catme -eq true ]], but this does not work either. Can someone point me in the right direction?

+3
source share
3

test [ - . test if, :

if $catme; then
    some commands
fi

man test, .

:

$ v=true  
$ $v
$ if $v; then
>   echo "PRINTED"
> fi
PRINTED

$ v=false
$ if $v; then
>   echo "PRINTED"
> fi
$ 
+8

:

if [[ true ]]; then echo +true; else echo -false; fi
+true
if [[ false ]]; then echo +true; else echo -false; fi
+true
if [[ 0 ]]; then echo +true; else echo -false; fi
+true
if [[ -1 ]]; then echo +true; else echo -false; fi
+true
if (( -1 )); then echo +true; else echo -false; fi
+true
if (( 0 )); then echo +true; else echo -false; fi
-false
if (( 1 )); then echo +true; else echo -false; fi
+true
if [[ true == false ]]; then echo +true; else echo -false; fi
-false
if [[ true == true ]]; then echo +true; else echo -false; fi
+true
if true; then echo +true; else echo -false; fi
+true
if false; then echo +true; else echo -false; fi
-false
+3

Give it a try [[ $catme == true ]].

Or better yet, gahooa's answer is pretty good.

0
source

Source: https://habr.com/ru/post/1788383/


All Articles