0

I've been trying to wrap my head around this for over an hour now and my searches haven't helped yield the answer.

Trying to set a variable inside a bash script. This variable is taking variable-A and removing variable-B from it.

Prefix="$(echo ${Process} | sed -e 's/${Server}//g')"

So if Process=abcd1wxyz01 and Server=wxyz01, then Prefix should end up being abcd1.

I've tried so many iterations from online searches I honestly can't recall what all I've tried.

0

2 Answers 2

2

Your problem are the quotes, as pointed out in afsal_p's answer.

You could do this with parameter expansion instead:

$ process=abcd1wxyz01
$ server=wxyz01
$ prefix=${process%"$server"}
$ echo "$prefix"
abcd1

The ${word%suffix} expansion removes suffix from the end of word.

Sign up to request clarification or add additional context in comments.

Comments

0

please use " instead of ' while using bash variables inside sed:

Prefix="$(echo ${Process} | sed -e "s/${Server}//g")"
echo $Prefix

2 Comments

echo "${Process}" or echo "$Process" would also be more correct than echo ${Process}; see BashPitfalls #14. Similarly, echo $Prefix should be echo "$Prefix"
Thank you so much for the clarification

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.