Bourne: if test completion status is completed

What is the difference:

if IsServerStarted ; then ...

and

if [ IsServerStarted -eq 0 ] ; then ...

It seems to me that these two statements should be equivalent? Oddly enough, the second statement is always true.

+3
source share
2 answers

Next, a shell function or an executable file $PATHwith the name is executed IsServerStarted, and if its exit code 0(i.e. true) starts a branch then. If such a function or executable does not exist, the exit code will not 0(i.e. False), but the branch thenwill be skipped.

if IsServerStarted ; then ...

[ (aka test), , IsServerStarted , 0, (IsServerStarted ) false. , [ 0 (.. ), then .

if [ IsServerStarted -eq 0 ] ; then ...
+8

, , , "IsServerStarted" . , -

var="IsServerStarted"
if [ IsServerStarted == "$var" ] ; then

( , ).

ndim , .

:

if $IsServerStarted ; then ...

if ( ), IsServerStarted. , IsServerStarted=true, if , true , true. IsServerStarted='grep popsicle freezer' and the, ` , , .

if [ $IsServerStarted -eq 0 ]; then ...

, . , .

0

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


All Articles