I'm not sure what is going on or which command causes the unexpected behavior, so I'll post everything I've done:
I have created a script onreceive.sh containing:
#!/bin/bash
read INCOMING
wall --nobanner "${INCOMING}.wav"
wall --nobanner "${INCOMING}"
Then I ran:
socat -u tcp-listen:7777,fork system:./onreceive.sh
Then I made a connection (I used PuTTY, but netcat probably works as well) to port 7777 and sent one line of text ("asdf").
The output I got is:
.wav
asdf
What I expected:
asdf.wav
asdf