Thanks for forwarding Seans great tip.
A few of questions though:
1. Do you really need the `-c`-flag (or the `-q1` in Seans version). To me it seems like it works without it? I've seen `-q1` used with UDP, but this is through TCP, insn't it? And according to my man page on OSX `nc`, `-c` means "Send CRLF as line-ending".
2. What benefit is there to piping through `cat`? My `nc` seems to handle stdin just lik cat. What am I missing?
3. Why do you set a variable based on `[ -n $SSH_CLIENT]` rather than using that directly in the `if`-statement?
Please note that I'm just curious, not trying to be a smart ass. There is a lot of things I don't know about shell scripts, so I'm asking to learn.
If you don't use -c, the script will just hang waiting for more input.
cat allows you to take STDIN input in a shell script.
I have a reusable snippet for setting the SSH_CLIENT variable that I use in scripts that have more logic. It's just easier.
Using -c on Mavericks only gives me a CRLF last in the output (Seen as ^M in VIM). Are we using different versions of nc?
And I see no difference in behavior of the script if I remove "cat |" from it.
I ended up with this line in .bashrc:
[ -n "$SSH_CLIENT" ] && alias pbcopy="nc localhost 2224"
Works so far, but I guess there is some scenario when it'll come back and bite me.
Anyway, thanks again for a great tip!
Also, your script is using alias instead of actually piping to the script. It works, just a different strategy. Thus you don't need cat.
load more (1 remarks)
It's quite possible that I've installed a version of netcat from brew. If I `cat testfile.txt | nc localhost 2224` it just sits there and waits for a ^d. -c fixes that.
load more (1 remarks)