Why the op of the following code is like this ????
i=4 j=-1 k=0
[ $i -o $j -o $k ]
echo $?
[ $i -a $j -a $k ]
echo $?
[ $i -a $j -o $k ]
echo $?
Why the op of the following code is like this ????
i=4 j=-1 k=0
[ $i -o $j -o $k ]
echo $?
[ $i -a $j -a $k ]
echo $?
[ $i -a $j -o $k ]
echo $?
Sorry. I don't understand the question.
Why is the output of the code like what? If you mean "what is the op", then 0, 0, 0.
I think the o/p should be 0 1 0
Why?
$? is a test of the success / failure of the last command, not whether the results of the variable are positive or negative. As you assigned values to the variables, the test [ ] is only testing that they are set, and says nothing of their values.
in unix 0 is true rest r false...am I right ???
Yes, that's normally the case.
But the test you are trying to make is not a numeric one, it's testing that the variables are set.
If you said this:
i=4 j=-1 k=0
[ $i -ne 0 -o $j -ne 0 -o $k -ne 0 ]
echo $?
[ $i -ne 0 -a $j -ne 0 -a $k -ne 0 ]
echo $?
[ $i -ne 0 -a $j -ne 0 -o $k -ne 0 ]
echo $?
0
1
0
Then you get the result you were looking for.