Comments on: New paper: Word expansion supports POSIX shell interactivity http://www.weaselhat.com/2018/03/15/expansion-supports-interactivity/ Sat, 17 Mar 2018 20:31:07 +0000 hourly 1 https://wordpress.org/?v=6.3.2 By: Ben Karel http://www.weaselhat.com/2018/03/15/expansion-supports-interactivity/comment-page-1/#comment-49389 Sat, 17 Mar 2018 20:31:07 +0000 http://www.weaselhat.com/?p=685#comment-49389 “but less so for interactive fork” — “work”?

When I read “ends up falling back on word expansion” I wasn’t sure what “falling back on” meant and (maybe because it comes after the reference to 4.3) didn’t realize that 4.3 would explore further. Moving the reference to 4.3 to the end of the paragraph might be clearer.

One idea for an example to illustrate word expansion: command prefixing/shortcuts. Basically, aliases/scripts of the form
foo -bar baz $@

Obviously echo is a degenerate case, but I think echo is (as you note) a little too tautological.
Three simple, non-degenerate cases that I’ve written:

cperfstat() { perf stat -e …MANY_EVENTS… “$@” }
silent() { “$@” >/dev/null }
timejson() { /usr/bin/time -f ‘JSON_FMT_STRING’ “$@” }

Of course, the downside of these examples is that the entire reason they’re shortcuts is that the long form is unwieldy.

This is a narrower but also more lightweight pattern of building & composing command lines than pipes. Note that two of these three case are wrappers around commands that are, themselves, wrappers! My examples where that’s not true tend not to be one-liners.

The interesting bit about the silent() example maybe less about word expansion and more about how things that look very different in non-shell languages (iteration vs stream redirection) are more harmonious in shell.

It might be interesting to examine Tcl and/or PowerShell for future work.

]]>