replace string in variable

Posted on 2004-10-20
Last Modified: 2010-04-21
hello, all

  i am coding a linux shell scripts, where a variabe "X1=ABCEDFG" is defined, how can i use other string, like "./",  to replace "X1=" ?

thanx in advance

Question by:kim_wei
  • 3
  • 2
LVL 18

Expert Comment

ID: 12358260
Not sure I understand your question.
Do you want a variable called "./" ?
If so I don't think you can as they are reserved metacharacters.
If not can you explain more?

Author Comment

ID: 12359410
hello, liddler,
  a piece of code like following,

echo $DEF_STR

  i just want to use "./" to replace "X1=", so it would look like,

DEF_STR="./ABCED", hopefully it is clear.

LVL 18

Expert Comment

ID: 12359569
you can use sed
sed 's/X1=/\.\//g' >

This will replace the string X1= with ./ wherever it appears in the file and save the output in

Author Comment

ID: 12367286
hello, liddler

   i really don't want to have additional file generated in my code, is it possible to perform this replacement only in scripts scope?

LVL 18

Accepted Solution

liddler earned 50 total points
ID: 12367383
but you can do:
sed 's/X1=/\.\//g' > && mv
to rename back to

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now