[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.
- Proposed: stop subjecting right-hand sides of `char` family requests to character translation, Douglas McIlroy, 2023/04/01
- Re: Proposed: stop subjecting right-hand sides of `char` family requests to character translation, G. Branden Robinson, 2023/04/01
- Re: Proposed: stop subjecting right-hand sides of `char` family requests to character translation,
Ralph Corderoy <=
- Re: Proposed: stop subjecting right-hand sides of `char` family requests to character translation, Douglas McIlroy, 2023/04/02
- Re: Proposed: stop subjecting right-hand sides of `char` family requests to character translation, Dave Kemper, 2023/04/10
- user-defined characters, translation maps, and environment binding (was: Proposed: stop subjecting right-hand sides of `char` family requests), G. Branden Robinson, 2023/04/24
- Re: user-defined characters, translation maps, and environment binding, Ralph Corderoy, 2023/04/24
- Re: user-defined characters, translation maps, and environment binding, G. Branden Robinson, 2023/04/24
- Re: user-defined characters, translation maps, and environment binding, G. Branden Robinson, 2023/04/24