groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proposed: stop subjecting right-hand sides of `char` family requests


From: Ralph Corderoy
Subject: Re: Proposed: stop subjecting right-hand sides of `char` family requests to character translation
Date: Sun, 02 Apr 2023 08:45:32 +0100

Hi Branden,

> Namely,
>
>     .tr @--@
>
> is not a no-op!

Is that surprising, even if troff isn't known?

    $ tr ab ba <<<abba
    baab
    $

> In fact, it works a lot like file descriptor redirections in the
> shell.
>
>     foo >/dev/null 2>&1 | grep error

That pipeline's not doing what ‘grep error’ suggests.  And tr and
redirection don't, to my mind, work in a similar manner.

Transliteration is conceptually done by a simple look-up table which is
only indexed once per character.  ‘tr a b’ or ‘.tr ab’ stores ‘b’ at
index ‘a’.  If ‘@--@’ were a no-op then how would swapping ‘@’ and ‘-’
be achieved?

Redirection is done left to right.  So the above pipeline maps stdout to
null and then stderr to stdout which is by now null.  It's ‘.tr 1n2n’ in
file-descriptor terms.  The grep for ‘error’ suggests ‘.tr 1n21’ is
wanted.

    $ ls error >/dev/null 2>&1 | grep error | nl
    $
    $ ls error 2>&1 >/dev/null | grep error | nl
         1      /bin/ls: cannot access 'error': No such file or directory
    $

If redirection were like transliteration then order wouldn't matter.
Just as ‘.tr 1n21’ and ‘.tr 211n’ are the same, these would be too.

    ls error      >/dev/null 2>&1
    ls error 2>&1 >/dev/null

Which would result in a loss of expression.

-- 
Cheers, Ralph.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]