A NOTE has been added to this issue. 
====================================================================== 
http://austingroupbugs.net/view.php?id=1105 
====================================================================== 
Reported By:                stephane
Assigned To:                
====================================================================== 
Project:                    1003.1(2016)/Issue7+TC2
Issue ID:                   1105
Category:                   Shell and Utilities
Type:                       Enhancement Request
Severity:                   Editorial
Priority:                   normal
Status:                     New
Name:                       Stéphane Chazelas 
Organization:                
User Reference:              
Section:                    awk 
Page Number:                 
Line Number:                 
Interp Status:              --- 
Final Accepted Text:         
====================================================================== 
Date Submitted:             2016-12-05 21:52 UTC
Last Modified:              2018-04-25 22:27 UTC
====================================================================== 
Summary:                    problems with backslashes in awk strings and EREs
====================================================================== 

---------------------------------------------------------------------- 
 (0003999) McDutchie (reporter) - 2018-04-25 22:27
 http://austingroupbugs.net/view.php?id=1105#c3999 
---------------------------------------------------------------------- 
> [...] for instance added a warning along the
> lines of "applications wishing to pass arbitrary strings by way
> of -v var="$value" or var="$value", should make sure backslashes
> are escaped or use the ENVIRON or ARGV methods instead" as that's
> a source of many bugs.

I second that.

> When it comes to regexps and escape sequences, it gets worse.

This also affects the replacement argument in sub() and gsub(). One of my
awk things outputs shell-quoted arguments for the shell to eval. To
shell-quote, on Solaris awk we need

    gsub(/'/, "'\\\\''");
    print ("'")($0)("'");

but on every other awk I've come across we need

    gsub(/'/, "'\\''");
    print ("'")($0)("'");

It seems obvious on the surface that the Solaris behaviour is a bug, but
the standard may be read to specify the unique Solaris behaviour. At the
sub(ere,repl[,in]) spec, it says for the "repl" argument: "An occurrence of
two consecutive <backslash> characters shall be interpreted as just a
single literal <backslash> character". But that is also specified for
double-quoted strings, so by the literal text of the standard, it seems
like double-escaping the backslashes is needed so Solaris is in the right
and everyone else in the wrong. 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2016-12-05 21:52 stephane       New Issue                                    
2016-12-05 21:52 stephane       Name                      => Stéphane Chazelas
2016-12-05 21:52 stephane       Section                   => awk             
2018-04-25 22:27 McDutchie      Note Added: 0003999                          
======================================================================


Reply via email to