I'm trying to read files with bash tcp socket,

So on one host I do,

nc -l 8888 < /etc/passwd

And on another machine,

echo </dev/tcp/

But it didn't read the file as expected, I got an empty line.

I know cat < /dev/tcp/xxx/xxxx works, but can I do that without external binaries?


So I tried $() syntax,

# echo $(</dev/tcp/ > file
bash: /dev/tcp/ No such file or directory
  • echo "$(</dev/tcp/" ? – 123 Apr 6 '16 at 9:39
  • echo doesn't do what you think it does. You probably meant to use cat. – user253751 Jun 13 '16 at 4:28

You can use a while loop:

while IFS= read -r line; do
    printf '%s\n' "$line"
done < /dev/tcp/localhost/8888

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.