Results 1 to 3 of 3
I am running bash 3.1 under Linux 2.6
When I try j=`expr $jp ^ $mori` it fails to recognize the "^". Replacing with a "+" works. A google search shows ...
- 01-08-2009 #1Linux User
- Join Date
- Mar 2008
- Posts
- 287
Where is my exclusive OR
I am running bash 3.1 under Linux 2.6
When I try j=`expr $jp ^ $mori` it fails to recognize the "^". Replacing with a "+" works. A google search shows that that operator is available but the text man page does not show it.
Can 1) someone explain this? 2) is there a work around so I can do an exclusive OR?
Thanks all.
- 01-08-2009 #2Linux User
- Join Date
- Jun 2007
- Posts
- 318
The expr (evaluate expression) utility doesn't recognize '^' as a valid oprator. The '+' simply means add the 2 no.s together, it isn't performing a XOR.
XOR is built into bash itself. Here's an example:
Code:# cat a.bash #!/bin/bash let "c=1^1" echo $c let "c=1^0" echo $c #./a.bash 0 1
- 01-09-2009 #3Linux User
- Join Date
- Mar 2008
- Posts
- 287
Thanks really big!! I tried both with and without quotes and the following returned:
mask=15
let mask=$mask^1
echo $mask ------------>14
let "mask=$mask^2"
echo $mask ------------>12
SuperLast edited by clickit; 01-09-2009 at 05:10 AM. Reason: Correction


Reply With Quote