How to retrieve variable value having dollar "$" in value
I am unable to retrieve complete value of variable having $ in middle of its name.
Eg: name=SsoFilterProdModeHandler$HttpServletRequestWrapperWithActions.class Now I want to retieve the variable "name" as complete value "SsoFilterProdModeHandler$HttpServletRequestWrapperWithActions.class" But actually its retriving "SsoFilterProdModeHandler" only. I know the shell treats the text after $ as an variable. But is there any way to retrieve the complete value. Thanks!! |
You need to embed the whole value with single quotes or use the escape character \ before $.
|
Thanks Colcuix!!
I tried using \\ escape character it works perfectly fine. The issue is I need to handle this while the variable is retrieved and I dont have to insert \\ in variable value. I am trying to use tr,sed,cut... Can you suggest a solution on this?? |
Try putting a backslash \ before the $.
*erm: some guys beat me to it. active forum here ;-) * |
It depends on how do you retrieve the variable. For example if I do:
Code:
$ var1=$(echo 'something$somethingelse') |
Now here is the special case.
I cant include escape character nor the single quotes in the variable or variable value. |
Quote:
|
Would you mind showing us exactly what you're doing, rather than just vaguely describing it? Give us some detailed examples of how you're setting the variables, and how you are trying to use them later, along with the actual and expected output.
The details can be very important in matters such as this. As one suggestion though, quotes can be combined. You can double-quote the part of the string that holds the variable, and single-quote the rest. http://mywiki.wooledge.org/Quotes Also, using the full expansion syntax can be used to separate variables embedded inside strings. Example: Code:
$ line="foobar" |
All times are GMT -5. The time now is 11:34 AM. |