Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • Very nice. Works only with a variable. i.e. echo $((1 ^= 1)) didn't work. Commented Jun 5, 2021 at 4:15
  • 1
    @Artfaith: That's because of the ^= assignment operator. The expression (( foo ^= 1 )) is equivalent to (( foo = foo ^ 1 )). Your example of ((1 ^= 1)) expands to (( 1 = 1 ^ 1 )) which fails because you can't change the value of 1. To make your example work, just use the regular XOR operator ^ instead of assignment, e.g.: echo $(( 1 ^ 1 )). Commented Feb 8, 2024 at 15:55