Let us say there is a variable in bash script with value \"001\" how can i write this binary data into a file as bits (as \"001\" not \"1\") echo writes it as string but i w
Just use the %b
in the printf:
printf "%b" "\012"
printf "%b" "\x0a"
%b - Print the associated argument while interpreting backslash escapes in there
so, above both prints binary value for the decimal 10
.
printf "%b" "\x0a" | od -bc
output
0000000 012
\n
you can even mix
printf "%b" "\12\xa\n" | od -bc
0000000 012 012 012
\n \n \n