Issue Details (XML | Word | Printable)

Key: PLXUTILS-44
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Sebastian Annies
Votes: 1
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Plexus Utils

Backslash is neither quoted nor escaped on Bash

Created: 21/Aug/07 10:32 AM   Updated: 03/Sep/07 01:54 PM
Component/s: None
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

Environment: Bash / Unix
Issue Links:
dependent
 


 Description  « Hide
The error occurs with Maven-SCM & continuum in my case. Maven-SCM creates following commandline:

/bin/bash -c "p4 -d /opt/continuum-1.1-beta-3-SNAPSHOT/apps/continuum/webapp/WEB-INF/working-directory/1 -cbackground-sojus-MavenSCM\opt\continuum-1.1-beta-3-SNAPSHOT\apps\continuum\webapp\WEB-INF\working-directory\1 sync"

the -c argument is created by:

Commandline command = PerforceScmProvider.createP4Command( repo, workingDirectory );
command.createArgument().setValue( "-c"+ specname );

the specname contains backslashes. The bash then removes the backslashes in specname. Ouch! That doesn't work. I think that CommandLine (or the underlying Shell) has to deal with this case. What do you think?

To test easily type:
/bin/bash -c "echo a
bc"

result: abc

Solution 1:
/bin/bash -c "echo a\\\\bc"
result: ab
c

Solution 2:
/bin/bash -c "echo 'a
bc'"

result: ab
c



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Sebastian Annies added a comment - 21/Aug/07 10:35 AM
Ignore the "To test easily type:" examples. I have difficulties with the wiki syntax:

To test easily type:
/bin/bash -c "echo a\bc"
result: abc

Solution 1:
/bin/bash -c "echo a\ \bc"
result: ab\c

Solution 2:
/bin/bash -c "echo 'a\bc'"
result: ab\c


Sebastian Annies added a comment - 03/Sep/07 01:54 PM
This is a pain in the ...

depending on the shell we start the bash we have to escape differently:

if the shell we start bash -c ... is not a bash (and is not using backslash () as an escape character) we have to escape backslash with backslash. But if the shell we start the bash in is itself a bash we have to add three more backslashes: The first call to the bash (the call that will start bash itself) makes 4 backslashes to 2 backslashes. The bash that has be instantiated by the call will now process the arguements again and will reduce the number of backslashes to just one backslash. OUCH. I hate unix