Bit mask in Bash
Yes, this is entirely possible:
#!/bin/bash
var1=0xA # (0b1010)
if (( (var1 & 0x3) == 0x2 ))
then
echo "Match"
fi
Bit manipulation is supported in POSIX arithmetic expressions:
if [ $(( var1 & 0x3 )) -eq $(( 0x2 )) ]; then
However, it's a bit simpler use an arithmetic statement in bash
:
if (( (var1 & 0x3) == 0x2 )); then