Matthew Hoggan
Matthew Hoggan

Reputation: 7604

Sed inside bash script not working: But it works on command line

I have tried the following on the command line and they work, but when I place them in a bash script I get an error (see below):

sed -e "s/INSERT_ME_HERE/"${ROOT_BUILD_HOME}"/g" ./Doxyfile > ./tmp && mv ./tmp ./Doxyfile
sed -e "s/INSERT_ME_HERE/'${ROOT_BUILD_HOME}'/g" ./Doxyfile > ./tmp && mv ./tmp ./Doxyfile
sed -e "s/INSERT_ME_HERE/`echo ${ROOT_BUILD_HOME}`/g" ./Doxyfile > ./tmp && mv ./tmp ./Doxyfile

The error I am getting is:

sed: -e expression #1, char 19: unknown option to `s'

However like I said I am using it from the command line and it works:

[mehoggan@hogganz400 Doxygen]$ ROOT_BUILD_HOME=MONKEY; sed -e "s/INSERT_ME_HERE/`echo ${ROOT_BUILD_HOME}`/g" ./Doxyfile | grep MONKEY
INPUT                  = MONKEY

Why does it work under one case and not the other?

Also ROOT_BUILD_HOME is set, I echo it right before the sed expression within the shell script.

echo `date`: "Going to run doxygen on source and move to ${ROOT_BUILD_HOME}";

Upvotes: 4

Views: 6103

Answers (2)

Sergey Benner
Sergey Benner

Reputation: 4431

#!/bin/bash

ABC=`echo ${ROOT_BUILD_HOME}`
echo $ABC
sed -e 's/INSERT_ME_HERE/'$ABC'/g' <./Doxyfile > ./tmp && mv ./tmp ./Doxyfile

hope this helps

Upvotes: 1

ruakh
ruakh

Reputation: 183602

I'm guessing that ROOT_BUILD_HOME starts with a /, which sed is interpreting as ending your replacement-string. Am I right? If so, then try using a different separator:

sed -e "s#INSERT_ME_HERE#${ROOT_BUILD_HOME}#g" ./Doxyfile > ./tmp && mv ./tmp ./Doxyfile

Upvotes: 5

Related Questions