I am writing a script to try and speed up my basic WordPress installation. It downloads the latest version, unpacks it, changes to the clients name and then updates some text in the config file.
I am however having trouble inserting multiple lines which contains special characters using sed. The multiple lines are from the WP Secret Key Generator https://api.wordpress.org/secret-key/1.1/salt/ and they are to replace the standard
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
etc…
Here is the bit of code that is giving me the issue
# Download data to variable
salt="`curl https://api.wordpress.org/secret-key/1.1/salt/`"
sed -i "/NONCE_SALT/a $salt" $pname/wp-config-sample.php
I am downloading the generated text to a variable and then looking to insert, on a new line, after the last instance in the standard text (I will later delete all of these standard lines). It throws up an error of;
"ed: -e expression #1, char 112: extra characters after command"
When I enter a single line of standard text it is fine. If I add quotation marks around the $salt it just prints the literal $salt in the file.
Is sed the right approach for inserting this data? Keeping in mind I need to insert after a specific point in the file?
Any hints or tips are more than welcome. This is my first attempt at a bash script.
The
afunction requires that a backslash precede any internal newline in the string. So, one approach is to usesedto add the necessary backslashes:(Note that I used
$(...)instead of`...`: the latter has painful quoting rules. In this case I’d have had to write\\\\instead of\\.)That said, in this case I think it might be simpler to save the salt-stuff to a temporary-file, and use
rinstead ofa: