4

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}";
1
  • Just a side note: instead of using a ./tmp you should give mktemp a try for such tasks since it improves the security and robustness of your scripts. Commented Sep 10, 2013 at 6:10

2 Answers 2

5

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
Sign up to request clarification or add additional context in comments.

3 Comments

That did the trick sir +1 for you. However, can you still explain why it would work on the command line and not in the script?
@Matthew because it only fails if the value of ROOT_BUILD_HOME contains a slash. The value in the script does, but "MONKEY" doesn't.
you can escape it \/. Or create a sed string with replacing / with \/ something like echo /home/|sed -e 's/\//\\\//g'
1
#!/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

2 Comments

Hope this one will give you more insight why it did work on script :)
I do not get what you need the ABC variable for. What would be different if you substituted the first two lines with echo ${ROOT_BUILD_HOME} or even echo $ROOT_BUILD_HOME?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.