1

I'm attempting to send a binary string to a program using ANSI-C quoted strings. This works fine:

echo $'\x23\x51\x66\x39\x01\x5f\x2f' | cat -v # output: #Qf9^A_/ 

However, if I have a NUL character (ASCII code 0) in the data, it terminates the string:

echo $'\x23\x00\x66\x39\x01\x5f\x2f' | cat -v # output: # 

I'm aware that strings in the C language are null-terminated so I'm guessing a similar constraint applies to this quoting method.

Is there a way I can send ASCII 0 to my program?

1 Answer 1

1

Try using printf instead of echo.

$ printf "\x23\x00\x66\x39\x01\x5f\x2f" | od -c 0000000 # \0 f 9 001 _ / 
1
  • Success! Thanks for the tip. Commented Nov 1, 2021 at 20:44

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.