Comment

Comment by Grimeton

What happened to /dev/tcp?

I mean you're not using unix sockets, but you can avoid the whole fifo <-> netcat <-> socket mess, by just doing:

  exec 3>/dev/tcp/127.0.0.1/6001 #(first display)
and then just using

  echo -n "something something" >&3
And if you want to disconnect:

  3<&-
Tools removed from the list: nc, mkfifo

And I'd also do the "append_file" trick a little bit different:

  declare -a SEND_BUFFER=()
  SEND_BUFFER+=($'\x1') # create window command ID
  SEND_BUFFER+=($'\x0') # depth
and so son. Bash has this special notation $'' that creates the escaped values when you use it (Check the "QUOTING" section in the man page). So

  echo -e "\n"
is the same as

  echo $'\n'
The difference is that you can add $'\n' to an array and then later do something like this:

  IFS=""
  echo "${SEND_BUFFER[*]}"
  unset IFS
This will output SEND_BUFFER as a "string" w/o any additional spaces or other separators.

So, this:

  declare -a foo=(a b c d e f)
printed like this:

  IFS=""; echo "${foo[*]}"; unset IFS;
turns into this:

  abcdef
You could use associative arrays and then assign names to the values, but the order of the entries is not stored and so you'd require a function that would build the string needed.

$0.02

parent Grimeton 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton