In Eclipse, when you specify arguments in the run dialog, Eclipse interprets ${foo}
as a request to use the Eclipse variable foo. I would like to pass a string to my application that contains ${foo}
but Eclipse treats this as an undefined variable and gives me an error.
-Dfoo "bar" --pattern "regex magic ${foo}"
Eclipse does not accept the single quote (') as a quoting character, instead it becomes part of the input. Does anyone know how I can escape ${foo}
in this dialog so it is interpreted as text and not a variable reference?
From the main menu, select Run | Edit Configurations or choose Edit Configurations from the run/debug configurations selector on the toolbar. In the Run/Debug Configurations dialog that opens, select a configuration where you want to pass the arguments. Type the arguments in the Program arguments field.
${foo} by itself can be escaped with $"{foo}".
When ${foo} is already part of a doubly-quoted string, as in your question, I'm not sure how or if it can be escaped.
I do not think there is any way to do this in Eclipse.
The offending bit of code is org.eclipse.core.internal.variables.StringSubstitutionEngine#substitute.
This is the bit of code that substitutes the ${foo} with whatever you've defined foo to be. Unfortunately, it can cope with nested and concatenated variables, so if dollar="$" and rest="{foo}" then ${dollar}${rest} gives ${foo} which gets evaluated again.
For info, in the code reportUndefinedVariables is hardcoded as true further up the stack, which is why you're getting the error message. There doesn't seem to be any way of changing it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With