[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


replace string in variable

Posted on 2004-10-20
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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' 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

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 150 total points
ID: 12367383
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

649 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