KornShell Test Team (ksh)

I have a question about the testing team in KornShell (ksh). I know that it is -neintended for comparing integers, and !=for comparing strings. How will the test command be executed if one argument is a string and the other is an integer? My code has the conditions below and they work fine.

The code:

myCount=1
myCount=`expr $myCount+ 0`
temp=`ps -aef | grep damn | wc -l`
if [ $temp -ne $myCount]; then
        echo ERROR Number
fi

if [ $temp != $myCount ]; then
        echo ERROR Strings
fi

Conclusion:

ERROR Number
ERROR Strings
+3
source share
3 answers

The type does not matter since it is a simple replacement for text. In other words, the value of the variable $tempwill be replaced instead $temp(for example).

, ksh , , 0. , , .

:

$ export s1=xyz
$ export s2=7xyz
$ export i1=0
$ if [ $i1 -eq $s1 ]
> then
>     echo equal
> fi
equal
$ if [ $i1 -eq $s2 ]
> then
>     echo equal
> fi
ksh: 7xyz: bad number `7xyz'

, , ksh.

, . .

+1

.

= ps -aef | grep damn | wc -l 1, grep, , , .

wc , -c grep.

:

= ps -aef |grep damn |grep -cv grep , damn, .

+1

ksh93 GNU coreutils expr 7.4. :

myCount=`expr $myCount+ 0`

myCount null, if "ksh: [: " . "". , ] .

myCount temp . myCount expr .

, , != > -ne -gt:

if (( $temp != $myCount ))
0
source

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


All Articles