1

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/127.0.0.1/8888

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?

EDIT

So I tried $() syntax,

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

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.