![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| replacing a number with random variable inside shell script | user_prady | Shell Programming and Scripting | 3 | 09-10-2007 11:44 PM |
| help in replacing ?? | zedex | Shell Programming and Scripting | 5 | 08-30-2007 10:45 PM |
| replacing variable values in all files in directories | newtoshell | Shell Programming and Scripting | 3 | 12-30-2005 01:11 PM |
| Replacing set of characters with a value of a variable | prekida | Shell Programming and Scripting | 1 | 07-26-2005 05:14 PM |
| Replacing pattern in variable | videsh77 | Shell Programming and Scripting | 1 | 05-26-2005 11:11 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Replacing $ in variable
hi
I have a variable like k=$DESTDIR/$PKG/$VERSION I want to replace each $ in string k with say "XXX". so that k becomes like this "XXXDESTDIR/XXXPKG/XXXVERSION" when I use echo $k | sed -e "s/\$/XXX" it actually passes expanded of variables $DESTDIR, $PKG and $VERSION to sed. Please help. Ashish |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Replacing "$" in variable
hi
I have a variable like k=$DESTDIR/$PKG/$VERSION I want to replace each $ in string k with say "XXX". so that k becomes like this "XXXDESTDIR/XXXPKG/XXXVERSION" when I use echo $k | sed -e "s/\$/XXX" it actually passes expanded of variables $DESTDIR, $PKG and $VERSION to sed. Please help. |
|
#3
|
|||
|
|||
|
probably the variable k is not formed correctly. Can you try echo $k and see if you get $DESTDIR/$PKG/$VERSION ? Are you forming the variable k like this : k="\$DESTDIR/\$PKG/\$VERSION" ? if so, the sed command works as expected.
|
|
#4
|
|||
|
|||
|
$DESTDIR/$PKG/$VERSION is coming from a read only file to k while reading.
|
|
#5
|
|||
|
|||
|
then, you need to see how to read it into k by escaping the $. can you tell us how you are reading it from the file and assigning to k ?
|
|
#6
|
|||
|
|||
|
I am using while loop like
while read k .....// if $DESTDIR is present in k then go to next line in file because DESTDIR is not defined . else use value of k as it is it may be $PKG/$VERSION as these variable are defined. ..... done < $file |
|
#7
|
|||
|
|||
|
Quote:
I feel that you need to escape $ by adding '\' everytime you append it to k. |
|||
| Google The UNIX and Linux Forums |