I have a script that contains a few variables. One of them is some proprietary path MYPATH.
I want to save the output of MYPATH and then replace another variable SOME_OTHER_PATH with the same value.
Current entry in myfile.sh
MYPATH="/opt/local/custom/myfiles"
SOME_OTHER_PATH=""
Output that I want
MYPATH="/opt/local/custom/myfiles"
SOME_OTHER_PATH="/opt/local/custom/myfiles"
The script that I wrote does this
mylocalpath=`sed -n /^MYPATH/p' myfile.sh | sed -e 's/MYPATH/'`
sed -i -e "s/^SOME_OTHER_PATH/${mylocalpath}" myfile.sh
There are two problems here
- Since
${mylocalpath}
contains "/", sed tries to evaluate these and throws an exception I would like to bundle the entire script in a sed file (instead of running sed twice) and execute it as
sed -f sed_file myfile.sh