op of logical operator


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting op of logical operator
# 1  
Old 08-16-2009
op of logical operator

Why the op of the following code is like this ????

Code:
i=4 j=-1 k=0
[ $i -o $j -o $k ]
echo $?
[ $i -a $j -a $k ]
echo $?
[ $i -a $j -o $k ]
echo $?

# 2  
Old 08-16-2009
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.
# 3  
Old 08-16-2009
I think the o/p should be 0 1 0
# 4  
Old 08-16-2009
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.
# 5  
Old 08-16-2009
in unix 0 is true rest r false...am I right ???
# 6  
Old 08-16-2009
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:
Code:
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

+= operator

im new to bash scripting and im just using online tutorials and trial and error. i wanted to write a script to read numbers from a file and find their sum: #!/bin/bash theSum=0 for line in $(cat numbers.txt) do let "theSum = theSum + $line" echo "$line" done echo "The sum is... (3 Replies)
Discussion started by: astrolux444
3 Replies

2. Shell Programming and Scripting

Logical error

I have this script to uvscan-update. Seems like that i am getting logical error at the end of the script. It is updating the script and also giving the error message to update it manually. I have deleted the DAT files to see if it will create new and it does. Below is the error and the script: ... (1 Reply)
Discussion started by: mk07md
1 Replies

3. UNIX for Dummies Questions & Answers

su with << operator

All, THe below is my script , when i use this i am getting nothing . could any one help me to know what is the use of the << operator below su - $8 << supo echo "exportsph $2 $1 $3 $4" exportsph $2 $1 $3 $4 supo i also tried as individual command su - userid << supo , when i do... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

4. Programming

new operator

Hi, Please clear the 2 questions, 2 Questions, 1) Why the new as a operator? Is there any special reason why it can't be a function like malloc? 2) How are we considering sizeof(),new are as a opearartors? I know + - * / -> , . etc.. are operators, which criteria satisfied by sizeof()... (4 Replies)
Discussion started by: Nagapandi
4 Replies

5. Shell Programming and Scripting

How to do logical AND and logical OR with grep

Hi can someone please help me on this. I need to perform this code: Grep any lines that meets the following criteria (A AND B) OR (A AND C) I tried this code, but it didn't work Grep-I "A &&B" | "A&&C" *.* $ thanks in advance (12 Replies)
Discussion started by: Needhelp2
12 Replies

6. Shell Programming and Scripting

logical OR in sed

frnds.. can i perform an OR operation in sed syntax ? if yes.. how? I need to search for some 2-3 mail addresses in multiple files and delete all those... and instead of them.. I need to insert a new mail id...( these are also other emails in that list .. which sud not be affected ) is... (8 Replies)
Discussion started by: clx
8 Replies

7. HP-UX

Or operator with if

hi, i was trying to club to test condition with if. if -o ; then it is giving me error message, i wanted to ask how can we check two condtions with one if. (1 Reply)
Discussion started by: babom
1 Replies

8. Shell Programming and Scripting

Logical OR using sed

Hello, This must be a novice question to you folks. But I searched through various places and did not find an answer to this question: How do we perform a logical OR operation using sed command? For example, I want to write a command that extracts all the text between pattern1 and pattern2 OR... (0 Replies)
Discussion started by: thejasviv
0 Replies

9. Shell Programming and Scripting

Multiple Logical Operator Issues ...

Hi folks I have a snippet of code Which is like this If ( ( A || B || C ) && D ) then Do some thing.... elif exit fi How to rephrase this and use it so I dont get any Errors ... Looking out for helpful replies .. Thanks & Regards Srikanth GR (1 Reply)
Discussion started by: srikanthgr1
1 Replies

10. Shell Programming and Scripting

And operator

I am trying to check two variables and if both are blank I want to set a flag: the_f3_pid=`rsh $target ps -ef | grep "f3.eab" | awk '{print $2}'` the_f7_pid=`rsh $target ps -ef | grep "f7.eab" | awk '{print $2}'` if ; then y=1 fi I get an error: ./script_name: test: 0403-021 ]... (4 Replies)
Discussion started by: rcarnesiii
4 Replies
Login or Register to Ask a Question