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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Linux script help 27 237
Is init file for an application part of rpm 3 39
what is this linux system is? 16 115
Problem to start Neon 20 54
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

19 Experts available now in Live!

Get 1:1 Help Now