LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-20-2011, 03:56 AM   #1
bharatlinux
LQ Newbie
 
Registered: Jul 2011
Posts: 3

Rep: Reputation: Disabled
Question 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!!
 
Old 10-20-2011, 03:59 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You need to embed the whole value with single quotes or use the escape character \ before $.
 
Old 10-20-2011, 04:05 AM   #3
bharatlinux
LQ Newbie
 
Registered: Jul 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
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??
 
Old 10-20-2011, 04:06 AM   #4
velle frak
LQ Newbie
 
Registered: Aug 2011
Distribution: debian wheezy
Posts: 5

Rep: Reputation: Disabled
Try putting a backslash \ before the $.

*erm: some guys beat me to it. active forum here ;-) *
 
Old 10-20-2011, 04:10 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
It depends on how do you retrieve the variable. For example if I do:
Code:
$ var1=$(echo 'something$somethingelse')
$ var2=$var1
$ echo $var2
something$somethingelse
it works flawlessly. Please, can you post the lines of code generating the string?
 
Old 10-20-2011, 04:54 AM   #6
bharatlinux
LQ Newbie
 
Registered: Jul 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Now here is the special case.

I cant include escape character nor the single quotes in the variable or variable value.
 
Old 10-20-2011, 06:16 AM   #7
velle frak
LQ Newbie
 
Registered: Aug 2011
Distribution: debian wheezy
Posts: 5

Rep: Reputation: Disabled
Quote:
Originally Posted by bharatlinux View Post
Now here is the special case.

I cant include escape character nor the single quotes in the variable or variable value.
Escape those too (e.g. \\ for \, \', etc.)?
 
Old 10-20-2011, 12:54 PM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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"

$ echo "thisisa$lineline"
thisisa

$ echo "thisisa${line}line"
thisisafoobarline
Oh, and please use [code][/code] tags around your code, to preserve formatting and to improve readability.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i create a global variable called "dogpatch" with a value of "woof" earthdog Linux - Newbie 9 12-15-2009 01:03 AM
How to get the "data type" of an "unknown variable" in "C Language" ? Affair Programming 8 06-20-2009 12:30 PM
"Failed to retrieve metadata" error with binhost Gentoo konqi Linux - Software 10 08-21-2008 05:50 AM
LXer: OLPC: Negroponte wants "zero dollar laptop" for children LXer Syndicated Linux News 0 03-10-2008 06:41 PM
"Broken" envirnment variable (MANPATH) and "/etc/profile.d" question. ErV Slackware 3 03-20-2007 09:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration