I need to pass binary data to a bash program that accepts command line arguments. Is there a way to do this?
It\'s a program that accepts one argument:
Save your binary data to a file, then do:
script "`cat file`"
Use the $'' quote style:
script $'\x02\xc5\xd8'
Test:
printf $'\x02\xc5\xd8' | hexdump -C
00000000 02 c5 d8
Bash is not good at dealing with binary data. I would recommend using base64 to encode it, and then decode it inside of the script.
Edited to provide an example:
script "$(printf '\x02\xc5\xd8' | base64 -)"
Inside of the script:
var=$(base64 -d -i <<<"$1")
How about this?
$ script "`printf "\x02\xc5\xd8"`"
script "`printf "\x02\xc5\xd8"`"
script "`echo -e "\x02\xc5\xd8"`"
test:
# echo -n "`echo -e "\x02\xc5\xd8"`" | hexdump -C
00000000 02 c5 d8 |...|