I have a binary in a variable and i want to invert it and store in a new variable. i mean, replace 0 with 1 and vice versa. I tried reading character by character with the below script but it didnt provide me the proper result.
#!/bin/bash
count=1
var1="00100011"
while [[ $count -le ${#var1} ]]
do
var2=$(expr substr $var1 $count 1)
if [ "$var2" -eq 1 ];
then
var3=0
else
var3=1
echo $var3
count=`expr $count + 1`
fi
done