Please find the code below where I want to add the variable value in between the XML tags. I am taking one string and my goal is to put them between the xml tags. Ex : in between <name> , <lname>
Kindly suggest a correction because while executing this script I am getting and output as : ${ary[0]} rather than the input variable.
str="rajneesh_kumar"
IFS=_
ary=($str)
for key in "${!ary[@]}"; do echo "$key ${ary[$key]}";
cat > "name.xml" <<- "EOF"
<?xml version="1.0" encoding ="UTF-8" standaalone="yes"?>
<rajneeshX xmlns="http://rajneesh.com">
<name> ${ary[0]}</name>
<lname> ${ary[1]}</lname>
</<rajneeshX >
That highly depends on the OS and shell versions that you are using. In recent shells (like bash and ksh ), you can do it immediately using "parameter expansion". If that's not the case, your OS may offer various tools like tr , sed , awk which can do this for you (with somewhat more effort / resource consumption).