leah blogs

July 2013

12jul2013 · Summer of Scripts: utter

When lr is ls the way I want it to be, utter is the equivalent for echo.

utter outputs each argument according to some rules: by default, it outputs each argument on its own line:

% utter foo bar baz
foo
bar
baz

But you can override the strings printed before, after, and inbetween the arguments:

% utter -b 'Simon says: ' -a $'!\n' foo bar baz
Simon says: foo!
Simon says: bar!
Simon says: baz!

There are two predefined modes. One for generating NUL-separated data:

% utter -z foo bar baz | od -c
0000000   f   o   o  \0   b   a   r  \0   b   a   z  \0
0000014

And one for verifying argument quoting:

% utter -q 'foo bar' baz
»foo bar« »baz«

utter does no escape processing at all, your shell probably can do that already.

I mostly use utter as in the first example, and frequently with -q. Why is it better than printf '%s\n'? It doesn’t output anything when no arguments are given.

NP: Fliehende Stürme—Die Axt

Copyright © 2004–2022