i have this script:
#!/bin/bash
exec 4>&1
nc localhost 100 0<&4 &
echo hello
echo ....
I just want to send hello and other things to netcat but that approach doesn't work.
I know echo "hello" | nc localhost works but i don't need it, same for "nc localhost 0<file.txt echo "hello" >file.txt.
Named pipe also work, but i'd want to know if something easy like above can be achieved.
I suggest you try Bash's coprocesses:
The above command starts
netcatin the background and links its standard input to file descriptor${nc[1]}and its standard output to${nc[0]}.You can then manipulate those file descriptors in order to replace your current stdin and stdout: