replace string in variable

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

kim
kim_weiAsked:
Who is Participating?
 
liddlerConnect With a Mentor Commented:
No,
but you can do:
sed 's/X1=/\.\//g' script.sh > script1.sh && mv script1.sh script.sh
to rename script1.sh back to script.sh
0
 
liddlerCommented:
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?
0
 
kim_weiAuthor Commented:
hello, liddler,
   
  a piece of code like following,

...
DEF_STR="X1=ABCED"
echo $DEF_STR
...

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

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

thanx
0
 
liddlerCommented:
you can use sed
sed 's/X1=/\.\//g' script.sh > script1.sh

This will replace the string X1= with ./ wherever it appears in the file script.sh and save the output in script1.sh
0
 
kim_weiAuthor Commented:
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?

thanx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.