Austin Group Defect Tracker

Aardvark Mark IV


Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0001892 [1003.1(2024)/Issue8] Shell and Utilities Editorial Clarification Requested 2024-12-12 03:40 2024-12-19 16:16
Reporter calestyo View Status public  
Assigned To
Priority normal Resolution Accepted As Marked  
Status Resolved  
Name Christoph Anton Mitterer
Organization
User Reference
Section 2.7 Redirection
Page Number 2493
Line Number 80966, ff.
Interp Status ---
Final Accepted Text Note: 0007021
Summary 0001892: definition of `{location}>redir-op word` does not specify whether a qouted location is still considered part of the redirection
Description Hey.

For the traditional n>redir-op style redirection, the standard says in line 80974:

> If n is quoted, the number shall not be recognized
> as part of the redirection expression.

First and as a side note, shouldn't that rather say "If ANY PART OF n is quoted…"?!
But that would be just "perfectionism".

My main point here is that no such sentence like the above seems to exist for the
  {location}redir-op word
style redirections, and {location} clearly does not fall under the definition "number n" from line 80972.

So by that, an supporting implementation would IMO be allowed to take e.g.:
  echo {location}>word
as the "new" style of redirections, or also as - what any non-supporting implementation would also do - taking the string `{location}` as first argument to echo.
Desired Action On page 2494, line 80985, insert:

    If any part of {location} is quoted it shall
    not be recognized as part of the redirection
    expression.
between "a shell variable." and "If this format is supported", with {location} being written in italics (or whatever else is used for marking such strings).


Optionally, on page 2493, 80974, insert:
    any part of
after the "If", so that the sentence reads "If any part of n …".
Tags tc1-2024
Attached Files

- Relationships

-  Notes
(0006994)
larryv (reporter)
2024-12-12 05:02

Desired Action:
On page 2494, line 80985, insert:
If any part of {location} is quoted it shall not be recognized as part of the redirection expression.
This agrees with bash 5.2 but disagrees with e.g. ksh93u+ 2012-08-01 and zsh 5.9:
% cat /tmp/austin-1892.sh
# Use eval to keep fatal errors contained.
eval 'echo hi {fd}>&1'
eval 'echo hi \{fd}>&1'
eval 'echo hi {\fd}>&1'
% bash /tmp/austin-1892.sh
hi
hi {fd}
hi {fd}
% ksh /tmp/austin-1892.sh
hi
hi {fd}
/tmp/austin-1892.sh[4]: eval[1]: \fd: invalid variable name
% zsh /tmp/austin-1892.sh
hi
(eval):1: parse error near `}'
hi {fd}
This portion of the proposal should be rejected. The standard already says (lines 80985-80986), "If this format is supported its behavior is implementation-defined." This covers the format's interaction with quoting, if any.
(0006995)
calestyo (reporter)
2024-12-12 05:19

I see.
Well if this is the case, then it's strange that the 2024 edition standardised (in the sense of "allowed") behaviour which make some of the previously only forms non-portable.

If that is indeed meant to be, than I'd revise my desired action, to add a warning or something alike explicitly mentioning that:
a) it's undefined whether or not quoting of {location} causes it to be not taken as part of the redirection
b) and consequently that any form where {location} is not separated by whitespace from redir-op is no longer guaranteed to be portable.
(0006996)
larryv (reporter)
2024-12-12 06:31

Note: 0006995:
Well if this is the case, then it's strange that the 2024 edition standardised (in the sense of "allowed") behaviour which make some of the previously only forms non-portable.
They were already nonportable because implementations had introduced {var}>file etc. in contravention of the previous standard. See 0001193:
Likewise, the standard does not permit the useful feature:
{var}>file
and related redirections because the grammar requires:
echo foo {var}>file
to be parsed such that {var} is a WORD to be expanded and passed to echo.
The cat was out of the bag; no point in pretending otherwise.

Note: 0006995:
If that is indeed meant to be, than I'd revise my desired action, to add a warning or something alike explicitly mentioning that:
a) it's undefined whether or not quoting of {location} causes it to be not taken as part of the redirection
b) and consequently that any form where {location} is not separated by whitespace from redir-op is no longer guaranteed to be portable.
As I said in Note: 0006994, I believe (a) is covered by the existing language. More useful than (b) would be something stating that applications that wish to avoid that format should ensure that one or more <blank> characters precede redir-op.
(0007000)
calestyo (reporter)
2024-12-12 14:40

> They were already nonportable because implementations
> had introduced {var}>file etc. in contravention of the
> previous standard.

In practise, yes. But if one just looks at the standard text for the previous edition, echo {var}>file should have portably caused {var} being the arg 1 for echo, at least for fully compliant implementations.

> I believe (a) is covered by the existing language

In principle yes (because behaviour is defined to be implementation-defined), but I thought it might be helpful to indicate that both behaviours actually exist in the wild.
But can live without.


> More useful than (b) would be something stating that applications
> that wish to avoid that format should ensure that one or more
> <blank> characters precede redir-op.

Well that's basically what I've meant.

What do you think about a sentence like:

   For portability, the application shall ensure
   that any {location} that is not meant to be part
   of a redirection is separated from redir-op by
   one or more <blank> characters.

Not sure though, were one should place it:
- If done somewhere below the:
    "The shell may support an additional format used for redirection:"
  it feels a bit as if the mandate to ensure is also part of
  the "may".
  Plus it may happen easier that people don't even read into the section,
  because they think they wouldn't use that feature anyway, while it may
  still affect them in the "normal" redirection form.
- If done above, and thus still in the section that explains the "normal"
  redirection form, then {location} hasn't been defined at that point, yet.
(0007001)
geoffclare (manager)
2024-12-12 15:07
edited on: 2024-12-12 15:10

The discussion here seems to have missed the relevant addition to the grammar, namely list item 3 in 2.10.1:
If the string contains at least three characters, begins with a <left-curly-bracket> ('{') and ends with a <right-curly-bracket> ('}'), and the delimiter character is one of '<' or '>', the token identifier IO_LOCATION may result; if the result is not IO_LOCATION, the token identifier TOKEN shall result.

In:
echo hi \{fd}>&1
the string does not start with '{' and so does not qualify for tokenisation as IO_LOCATION. The other two example cases do, but as Note: 0006994 points out the behaviour is implementation-defined and so how it is affected by any quoting characters inside the curly brackets is for implementations to decide.

Regarding the question in the Description:

> shouldn't that rather say "If ANY PART OF n is quoted…"

Yes it should. List item 2 in 2.10.1 is:
If the string consists solely of digits and the delimiter character is one of '<' or '>', the token identifier IO_NUMBER shall result.
If any quoting characters are present, then "the string consists solely of digits" is not true and the condition is not satisfied.

(0007021)
geoffclare (manager)
2024-12-19 16:15

On page 2493 line line 80974 section 2.7 Redirection, change:
If n is quoted, the number shall not be recognized ...
to:
If any part of n is quoted, the number shall not be recognized ...

- Issue History
Date Modified Username Field Change
2024-12-12 03:40 calestyo New Issue
2024-12-12 03:40 calestyo Name => Christoph Anton Mitterer
2024-12-12 03:40 calestyo Section => 2.7 Redirection
2024-12-12 03:40 calestyo Page Number => 2493
2024-12-12 03:40 calestyo Line Number => 80966, ff.
2024-12-12 05:02 larryv Note Added: 0006994
2024-12-12 05:19 calestyo Note Added: 0006995
2024-12-12 06:31 larryv Note Added: 0006996
2024-12-12 14:40 calestyo Note Added: 0007000
2024-12-12 15:07 geoffclare Note Added: 0007001
2024-12-12 15:09 geoffclare Note Edited: 0007001
2024-12-12 15:10 geoffclare Note Edited: 0007001
2024-12-19 16:15 geoffclare Note Added: 0007021
2024-12-19 16:16 geoffclare Interp Status => ---
2024-12-19 16:16 geoffclare Final Accepted Text => Note: 0007021
2024-12-19 16:16 geoffclare Status New => Resolved
2024-12-19 16:16 geoffclare Resolution Open => Accepted As Marked
2024-12-19 16:16 geoffclare Tag Attached: tc1-2024


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker