[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ${| command; } funsub not setting REPLY does not error out with 'set
From: |
Chet Ramey |
Subject: |
Re: ${| command; } funsub not setting REPLY does not error out with 'set -u' active |
Date: |
Mon, 23 Dec 2024 11:50:00 -0500 |
User-agent: |
Mozilla Thunderbird |
On 12/20/24 11:04 AM, Zachary Santer wrote:
Explicitly attempting to expand any one of those with a parameter
expansion when it's unset and 'set -u' is active will cause bash to
error out. ${| command; } is likewise also an explicit attempt to
expand the value of a variable, this time the instance of REPLY local
to the funsub.
Your view of `explicit' is, um, unorthodox.
By contrast, the expansions of, or other references to, variables like
PS2 and PS4 that bash makes internally are implicit. For many of the
variables listed in that portion of the "Shell Variables' section of
the manual, It's a perfectly valid state for them to be left unset.
You don't always need a TMOUT, an LC_ALL, or a FUNCNEST, for instance.
Bash knows what to do without them.
Bash knows what to do when a funsub leaves REPLY unset as well. Maybe
the best way to think about it is COMPREPLY. Leaving COMPREPLY unset is
a valid, if unusual, way to indicate that there are no possible
completions.
In the same way, leaving REPLY unset in a funsub is a valid, if unusual,
way to indicate that the funsub produces no output. Command substitutions
produce no output all the time.
So the purpose of 'set -u' still applies. If I, as the programmer,
managed to misspell REPLY or forget to set it in some codepath, I'd
rather bash tell me that than have it silently expand ${| command; }
to nothing and leave me scratching my head as to what's going on,
given breakage potentially evident only later in the script.
You still have to check whether REPLY expands to the empty string. How
is that different?
This sounds like something a tool like `shellcheck' should warn about.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
Description: OpenPGP digital signature
- ${| command; } funsub not setting REPLY does not error out with 'set -u' active, Zachary Santer, 2024/12/18
- Re: ${| command; } funsub not setting REPLY does not error out with 'set -u' active, Lawrence Velázquez, 2024/12/18
- Re: ${| command; } funsub not setting REPLY does not error out with 'set -u' active, Chet Ramey, 2024/12/19
- Re: ${| command; } funsub not setting REPLY does not error out with 'set -u' active,
Chet Ramey <=
- Re: ${| command; } funsub not setting REPLY does not error out with 'set -u' active, Zachary Santer, 2024/12/24
- Re: ${| command; } funsub not setting REPLY does not error out with 'set -u' active, Lawrence Velázquez, 2024/12/24
- Re: ${| command; } funsub not setting REPLY does not error out with 'set -u' active, Zachary Santer, 2024/12/25
- Re: ${| command; } funsub not setting REPLY does not error out with 'set -u' active, microsuxxor, 2024/12/25