Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sed error with directory

I'm trying to use sed to replace some directories over a file. This is how I'm using the sed to replace.

sed -i "s/location_apache/$CUSTOM_INSTALL_HOME/g" $apache_boing

Now, the problem comes with the $CUSTOM_INSTALL_HOME variable. Because is a directory.
Every time I tried to run the script I got this error.
sed: -e expression #1, char 22: unknown option to `s'
I know this is because the missing \ on the $CUSTOM_INSTALL_HOME variable

There is any workaround for this issue?

Thanks

like image 667
radicaled Avatar asked Sep 13 '25 05:09

radicaled


1 Answers

Since $CUSTOM_INSTALL_HOME has forward slash / you can use a different delimiter like hash # in sed:

sed -i "s#location_apache#$CUSTOM_INSTALL_HOME#g" $apache_boing
like image 154
anubhava Avatar answered Sep 14 '25 21:09

anubhava