Will Lauer commented on PIG-5362:

Updating the patch to clarify the unit test.

Backslash is treated by the shell as an escape character when not surrounded by 
appropriate quotes. This gets confusing when combined with Java's quoting of 
slashes. So {{\\}} in java becomes {{\}} being passed to the shell. Depending 
on how {{$\stuff}} gets interpretted by both the shell and by echo, the {{\}} 
character may or may not be considered an unassociated escape. To avoid all 
this confusion, quoting the command with single quotes clarifies for the shell 
how escapes should be handled. So {{"echo '$\\stuff'"}} becomes the command 
{{echo '$\stuff'}} passed to the shell, and produces the output {{$\stuff}} for 
java to ingest and assign back to the parameter in Pig.

> Parameter substitution of shell cmd results doesn't handle backslash  
> ---------------------------------------------------------------------
>                 Key: PIG-5362
>                 URL: https://issues.apache.org/jira/browse/PIG-5362
>             Project: Pig
>          Issue Type: Bug
>          Components: parser
>            Reporter: Will Lauer
>            Priority: Minor
>         Attachments: pig.patch, pig2.patch, pig3.patch
> It looks like there is a bug in how parameter substitution is handled in 
> PreprocessorContext.java that causes parameter values that contain 
> backslashed to not be processed correctly, resulting in the backslashes being 
> lost. For example, if you had the following:
> {code:java}
> %DECLARE A `echo \$foo\\bar`
> B = LOAD $A 
> {code}
> You would expect the echo command to produce the output {{$foo\bar}} but the 
> actual value that gets substituted is {{\$foobar}}. This is happening because 
> the {{substitute}} method in PreprocessorContext.java uses a regular 
> expression replacement instead of a basic string substitution and $ and \ are 
> special characters. The code attempts to escape $, but does not escape 
> backslash.

This message was sent by Atlassian JIRA

Reply via email to