I am writing a ksh script which processes a path variable containing @sys
substring to its corresponding OS name:
If build_type
is is of 64bit version we need to append .64
at the end of osver
.
e.g. if opsys=amd64_linux26_rh5
(Red Hat Enterprise Linux 5) and build_type=dbg64
, osver
should be amd64_linux26_rh5.64
.
Now, I want to replace @sys
present in file_path
variable with its corresponding OS version as a substring i.e. amd64_linux26_rh5.64
.
But it looks like sed
is ignoring . somehow and the only amd64_linux26_rh5
is replacing @sys
omitting the .64
part.
#!/bin/ksh
file_path="/xxx/xxx/xxx/@sys/xxx"
sys="@sys"
bld_type="dbg64"
opsys="amd64_linux26_rh5"
bitver=".64"
if [[ ${bld_type} = @(*64) ]]
then
osver="${opsys}${bitver}"
fi
echo "osver: $osver"
echo "old file_path is : $file_path"
file_path=$(echo "$file_path" | sed "s/$sys/${osver}/")
echo "new file_path is : $file_path"
The corrosponding output:
osver: amd64_linux26_rh5.64
old file_path is : /xxx/xxx/xxx/amd64_linux26_rh5/xxx
new file_path is : /xxx/xxx/xxx/amd64_linux26_rh5/xxx
We are trying to change file_path
to /xxx/xxx/xxx/amd64_linux26_rh5.64/xxx
. Please suggest an appropriate way use sed
in this case.