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:
script arg1
But instead of the string arg1
, I'd like to pass some bytes that aren't good ASCII characters - in particular, the bytes 0x02
, 0xc5
and 0xd8
.
How do I do this?
bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc. Place variables in quotes if the values might have spaces in them.
Using arguments Inside the script, we can use the $ symbol followed by the integer to access the arguments passed. For example, $1 , $2 , and so on. The $0 will contain the script name.
NUM} ) in the 2^32 range, so there is a hard limit somewhere (might vary on your machine), but Bash is so slow once you get above 2^20 arguments, that you will hit a performance limit well before you hit a hard limit.
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 |...|
Use the $''
quote style:
script $'\x02\xc5\xd8'
Test:
printf $'\x02\xc5\xd8' | hexdump -C 00000000 02 c5 d8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With