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
    Commented Apr 6, 2016 at 9:39
  • echo doesn't do what you think it does. You probably meant to use cat. Commented Jun 13, 2016 at 4:28

1 Answer 1


You can use a while loop:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .