'bash - unable to replace text with special symbols and spaces
Here is my script:
#!/bin/bash
authConfig="./auth/phinx.php"
read -p "Enter MySQL Auth database name: " databaseName
databaseSearch="'name' => 'development_db'"
replaceDatabase="'name' => '$databaseName'"
if [[ $databaseName != "" ]]; then
sed -i -e "s/$databaseSearch/$replaceDatabase/g" $authConfig
fi
Here is the content of phinx.php:
<?php
return
[
'paths' => [
'migrations' => '%%PHINX_CONFIG_DIR%%/db/migrations',
'seeds' => '%%PHINX_CONFIG_DIR%%/db/seeds'
],
'environments' => [
'default_migration_table' => 'phinxlog',
'default_environment' => 'development',
'production' => [
'adapter' => 'mysql',
'host' => 'localhost',
'name' => 'production_db',
'user' => 'root',
'pass' => '',
'port' => '3306',
'charset' => 'utf8',
],
'development' => [
'adapter' => 'mysql',
'host' => 'localhost',
'name' => 'development_db',
'user' => 'root',
'pass' => '',
'port' => '3306',
'charset' => 'utf8',
],
'testing' => [
'adapter' => 'mysql',
'host' => 'localhost',
'name' => 'testing_db',
'user' => 'root',
'pass' => '',
'port' => '3306',
'charset' => 'utf8',
]
],
'version_order' => 'creation'
];
It looks like sed can't find the string. Why is that and where is my mistake?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
