Skip to content

Instantly share code, notes, and snippets.

Created May 22, 2012 13:36
What would you like to do?
Replace a token in a file from a Bash script using Perl
perl - /var/www/html/wp-config.php <<'EOF'
use strict;
use warnings;
$^I = '.bak';
my $keys = `curl -sS`;
while(<>) {
if (/\{KEYS_TOKEN\}/){
print $keys;
} else {
Copy link

This snippet is derived from a larger Bash script used in an Amazon AWS CloudFormation template. The idea is that earlier in the template, the WordPress wp-config.php file is created with "{KEYS_TOKEN}" in the middle. The actual keys must be injected into the middle of the file, and not appended to the end. This code accomplishes that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment