Live data from Hacker News

Awkward – A Node.js-based terminal emulator

github.com

61–64 of 64 posts

Re: Awkward – A Node.js-based terminal emulator

#61
post #60

I'm imagining a world where coreutils and built-ins all respect an environment variable, say STDOUT_JSON=1 , and would output JSON. That would be a great start. Especially if the JSON-Schema could be output with a new built-in, manj . How Herculean of a task is this?

Not a good idea. Imagine that you invoke some program A that in turn invokes a coreutils program B. Imagine that A has been written before today (in other words, it is not aware of the STDOUT_JSON technique). Since A and B inherit the STDOUT_JSON environment variable, A will receive JSON. But it is not expecting this, so it will probably crash.

Thanks for that answer, that lead me to learn and understand more about standard streams and file descriptors than I ever cared to before! That's a good thing. :)

So then, what about this approach: since the de-facto standard streams are STDIN, STDOUT and STDERR using file descriptors 0, 1 and 2, respectively, are there three more reserved numbers (I couldn't find any in my google-glance) that could be used for, say, JSONIN, JSONOUT and JSONERR?

I think the heart of the matter is: unless it becomes part of the POSIX standard, is there any hope on agreeing on an informal "UNIX philosophy" sort of approach that would allow coreutils and shell built-ins to accept and pass structured responses in any kind of object form?

Re: Awkward – A Node.js-based terminal emulator

#62

FWIW, I've been using Groovy for this purpose to encapsulate processes in *Nix and Windows. Not perfect, not lightweight, but happens to get the job done.

Apache Groovy's perfect for these kind of tasks where it doesn't need to be lightweight. Just don't use it for building actual applications -- build them in a decent typed language like Java, Scala, or Kotlin, then use Groovy as a multi-OS version of Bash to automate builds, tests, and runs.

Re: Awkward – A Node.js-based terminal emulator

#63
post #58
post #21

The following comment could apply to hundreds of similar submissions to HN in recent years. Many people -- many of them young people I suspect -- have invested a lot of time learning Javascript. It has become a very popular language. But it remains to be seen whether Javascript will be as long lasting as the UNIX shell and standard utilties. Historically speaking, computer languages have been known to fall into and o…

What mainstream languages, especially if standardized or open sourced, have you seen be completely abandoned? Even Cobol, Fortran and Lisp are still active. Javascript as this moment probably has the highest number of programmers using it. It is standardized and has several competing state-of-the-art OSS implementations. It's going go be with us, at least as legacy code, for decades :)

Agree. Legacy code.

Re: Awkward – A Node.js-based terminal emulator

#64
Sorry I'm late to this, but I'm a big AWK fan, I use it daily and have done so for years. For sysadmin things its great for doing data manipulation in shell scripts.

I get that Awkward is a shell, and I can see the use. But it seems very clunky to use.

This AWK script was posted in this thread

      ps | awk 'NR>1{ print $1, $4}'
It takes the output of the PS command, tosses the header away and then prints the value of the first and fourth fields out. This data can be piped to other programs for additional processing.

The NR>1 idiom is pretty well known after you look at a few example scripts that use it. To replicate the scrip that the Awkward video uses, it's just

      ps | awk '{ print $1, $4}'
It's shorter than the Awkward example. I think it's simple, for every line you get from PS print the first set of text and the fourth set of text. Not sure what Awkward would need to do to skip the header.

@erikrothoff makes a point about whats the value in knowing AWK over JS. I'd like to think that it gives you a powerful portable tool that can be used as either a stand alone application or as part of a shell script. If you are a Windows user, then it's not going to fit as well, but if you are a Unix/Linux/OS X user, it's a worthy tool to add to your arsenal.

The syntax may be "some of the least intuitive code" but investing about 20 minutes can fix that. There are lots of tutorials that can give you a quick leg up. There are also a few "one line AWK scripts" collections that are good samples.

One of the most powerful things about AWK is the ability to use regular expressions to see if you want to process the record. The ability to go through a file, pluck out the record(s) and process them is very nice.

    ps | awk '/astro/ {print $1, $4}'
will give me any user that has astro in it. Not sure how that would work in Awkward. The use of regular expressions like this is what makes AWK a go to language for text processing.

Not here to add to the AWK vs Javascript debate, but wanted to add AWK is a powerful tool, having it in your toolbox is a good thing.

Post reply on HN