Shell script to find & replace value in xml

eleanorsnake

New Member
I have a xml config file called config.xml:\[code\]<?xml version="1.0" encoding="UTF-8"?><config> <server-ip>192.168.1.45</server-ip> <server-port>1209</server-port> <repository-temp-path>/home/john</repository-temp-path></config>\[/code\]I have a shell script to configure the values of "server-ip", "server-port" and "import-path" with $1,$2,$3:\[code\]#!/bin/shif [ $# -ne 3 ];thenecho "usage: argument 1:IP_Address 2:Server_PORT 3:Temp_PATH"exit 1fiIP=$1PORT=$2DIRT=$3echo "Change values in config.xml..."sed "s/<server-ip>.*<\/server-ip>/<server-ip>$IP<\/server-ip>/;s/<server-port>.*<\/server-port>/<server-port>$PORT<\/server-port>/;s/<repository-temp-path>.*<\/repository-temp-path>/<repository-temp-path>$DIRT<\/repository-temp-path>/" config.xml > config2.xmlecho "Done."\[/code\]But it only works for the "$ ./abc.sh a b c", and not work for "$ ./abc.sh 192.168.1.6 9909 /home/bbb".... can you help to get it working and end up with a better solution?
 
Back
Top