Comment

Comment by 1vuio0pswjnm7

This does not seem obscure to me at all. Having learned about C from reading djb's programs, I write programs that read their arguments from environmental variables. (See djbdns for example.) When I run one of these programs it's common to set variables on the command line, e.g.,

   echo https://example.com|Connection=keep-alive yy025|nc -vvn 127.127 80
yy025 sets the HTTP Connection header according to the value of the corresponding environmental variable. If I want to send a POST request I set the variable httpMethod to POST. The address 127.0.0.127 is a TLS forward proxy. Original netcat allows one to type 127.127 without the zeros.

Using djb's envdir utility, one can put a selection of different HTTP headers into a directory so that there's no need to type them on the command line.

    cd /path/to/dir
    echo close > connection
    echo aplication/x-www-form-urlencoded > content-type
    echo id=123\;key=xyz > cookie
    echo 19 > content-length
    echo POST > httpMethod
    echo /api/whatever > path
    echo "{ \"key\": \"value\" }" > post-data
    cd
    echo https://example.com \
    |if cd /path/to/dir;envdir . yy025;then 
    cat post-data;fi \
    |nc -vvn 127.127 80
It's strange to me to see this author use printenv instead of set (a built-in) to display Bourne shell environmental variables. As someone who uses Bourne shell every day and on a variety of computers, I never use printenv. On the smaller systems I make, I do not include printenv in the userland.

The use of fgrep to match a single word in all caps is also strange.

Maybe I am just missing some UNIX wisdom here. If so, please disregard this comment.

From the article

  $ export FRED=value
  $ printenv | fgrep FRED
  FRED=value
  $ FRED=
  $ printenv | fgrep FRED
  FRED=
  $ unset FRED
  $ printenv | fgrep FRED
  $ # ie, no output from printenv
Without using printenv or grep -F (in shell script /bin/fgrep)

  $ export FRED=value
  $ set|grep FRED
  FRED='value'
  FRED=
  $ set|grep FRED
  FRED=''
  $ unset FRED
  $ set|grep FRED
  $ # ie, no output from set

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton