i like the currently showed behavior of '\' parsed as arg no need to error .. if u meant that, ..
On Mon, Feb 14, 2022 at 11:17 PM Chet Ramey <chet.ra...@case.edu> wrote: > On 2/13/22 3:15 PM, vzvz...@gmail.com wrote: > > > Bash Version: 5.0 > > Patch Level: 17 > > Release Status: release > > > > Description: > > > > Background > > ---------- > > > > Commit a0c0a00fc419b7bc08202a79134fcd5bc0427071 (bash-4.4) introduced a > change in parse.y with following documentation in the change logs: > > > > parse.y > > - shell_getc: if bash is reading input from a string that ends > with an > > unquoted backslash, add another backslash instead of a newline, > since > > the backslash and newline will disappear in normal processing. > Fixes > > bug with `bash -c 'eval \\; echo y' ' skipping the eval command > and > > setting incorrect exit status, and `bash -ic 'eval \\; echo y' ' > > seeing EOF on empty line and exiting before the echo. Keep > track of > > backslash state with last_was_backslash; set in char reading > loop. > > Fixes bug reported by Eduardo A. Bustamante López < > dual...@gmail.com> > > > > The new code in parse.y > > > > /* Don't add a newline to a string that ends with a backslash if > we're > > going to be removing quoted newlines, since that will eat the > > backslash. Add another backslash instead (will be removed by > > word expansion). */ > > if (bash_input.type == st_string && expanding_alias() == 0 && > last_was_backslash && c == EOF && remove_quoted_newline) > > shell_input_line[shell_input_line_len] = '\\'; > > else > > shell_input_line[shell_input_line_len] = '\n'; > > shell_input_line[shell_input_line_len + 1] = '\0'; > > > > > > This specific change is also there in commit > 0385211bb5cb01e0259c64ec2c5cc6337d4e215c on a development branch. > > > > Observed vs. expected behaviour > > ------------------------------- > > > > The mentioned bug is indeed fixed by this change. However, in case of > another edge case following new behaviour is observable: > > > > $ bash -c 'echo \' > > \ > > $ # backslash appears on output > > I think the behavior of a word consisting only of a backslash is officially > unspecified. > > It's not a quote character -- there's nothing to quote -- so it's not > removed by quote removal. > > In general, I think it's better to err on the side of preserving output > here. > > Existing shell behavior varies, so you can't really count on anything. > > -- > ``The lyf so short, the craft so long to lerne.'' - Chaucer > ``Ars longa, vita brevis'' - Hippocrates > Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/ > >