First, you don't need cat
with grep
. That is enough:
x="$(grep ConfigPath /scratch/env.properties)"
Second, I believe this is not an assignment you want:
y=$(ConfigPath=/scratch/a/b)
If you want variable y
to hold ConfigPath=/scratch/a/b
string it should be:
y="ConfigPath=/scratch/a/b"
$(...)
is a command substitution in Bash.
Third, you should use double quotes in sed
command to make shell expand x
and y
:
sed "s/$x/$y/" env.properties
Also notice that /
is a poor choice when working with Unix paths
because it is the delimiter. Use another character, for example
comma:
sed "s,$x,$y," env.properties
As noted by user
Kusalananda
in the comment below you make this easier and better by using sed
only and
making sure that ConfigPath
is at the beginning of the line:
sed "s,^ConfigPath=.*$,ConfigPath=/scratch/a/b," env.properties