I am having a hard time trying to make sed work to apply the substitution operation bellow.
SALT=$(curl -L https://api.wordpress.org/secret-key/1.1/salt/)
#SALT='test' #this of course works fine
#echo $SALT
sed -i "s/salt_here/$SALT/g" wp-config.php
Inside the file "wp-config.php" there is a line with the word "salt_here" (without quotes). However, the $SALT variable has a lot of garbage, so I am getting this error:
sed: -e expression #1, char 78: unknown option to `s'
Is there a way to escape all the garbage inside a variable (just like php's http://php.net/preg_quote)
UPDATE:
This is the best I can get:
SALT=$(curl -L https://api.wordpress.org/secret-key/1.1/salt/ | sed 's/\(\/\|\\\|&\)/\\&/g')
SALT1=`/usr/bin/php << EOF
<?php echo preg_quote("$SALT"); ?>
EOF`
#echo "$SALT1"
cp '/home/public_html/zz_f/wp-config.php' '/home/public_html/zz_f/wp-config_t.php'
sed -i "s/salt_here/$SALT1/g" wp-config.php
But still with an error:
PHP Parse error: syntax error, unexpected '>', expecting T_VARIABLE or '$' in - on line 3
sed: -e expression #1, char 12: unterminated `s' command