Bash shell trying to create and evaluate a mask

I am trying to create a mask and use the bitwise operator "&" to compare with another variable and see the result. Let there be a code:

mask=00000
mesk=00010
mosk=$mask&$mesk
echo $mosk
echo meec

I am trying to extend this functionality to have more characters (different error / success codes), but these lines just don't work. Executing the script will print an empty line, then "meec" ,.

I came from object-oriented programming, and although I have read several documents on this subject, something seems to me to be missing. Any help would be appreciated.

Edit: for some reason the code does not work, it says: "command 00010 not found"> ​​_>

+4
source share
1 answer

This is because usually a character &in a shell is a modifier for entering a command in the background.

You should use the Bash Arithmetic Extension (for example) to work it:

mosk=$(($mask & $mesk))
+4
source

All Articles