i am trying to write a bash script that will configure my phpmyadmin, i want to create the config.inc.php file and append the configuration file to it and the file contain a blowfish secret with this function $(openssl rand -base64 50)
, it created the file but instead of adding the result of $(openssl rand -base64 50)
, it added $(openssl rand -base64 50)
to the file.
Here is the code
phpmyadmin_config='
<?php
declare(strict_types=1);
$cfg["blowfish_secret"] = "$(openssl rand -base64 50)";
$i = 0;
$i++;
$cfg["Servers"][$i]["auth_type"] = "cookie";
$cfg["Servers"][$i]["host"] = "localhost";
$cfg["Servers"][$i]["compress"] = false;
$cfg["Servers"][$i]["AllowNoPassword"] = false;
$cfg["UploadDir"] = "";
$cfg["SaveDir"] = "";
$cfg["TempDir"] = "/var/lib/phpmyadmin/tmp";
'
echo -e "$phpmyadmin_config" >> /usr/share/phpmyadmin/config.inc.php
Please what am i doing wrong,
Like this, using shell here-doc:
cat<<EOF1 > /usr/share/phpmyadmin/config.inc.php
<?php
declare(strict_types=1);
\$cfg["blowfish_secret"] = "$(openssl rand -base64 50 | tr -d '\n')";
EOF1
cat<<'EOF2' >> /usr/share/phpmyadmin/config.inc.php
$i = 0;
$i++;
$cfg["Servers"][$i]["auth_type"] = "cookie";
$cfg["Servers"][$i]["host"] = "localhost";
$cfg["Servers"][$i]["compress"] = false;
$cfg["Servers"][$i]["AllowNoPassword"] = false;
$cfg["UploadDir"] = "";
$cfg["SaveDir"] = "";
$cfg["TempDir"] = "/var/lib/phpmyadmin/tmp";
EOF2
You can't expand variables in single quotes.
Learn how to quote properly in shell, it's very important :
"Double quote" every literal that contains spaces/metacharacters and every expansion:
"$var"
,"$(command "$var")"
,"${array[@]}"
,"a & b"
. Use'single quotes'
for code or literal$'s: 'Costs $5 US'
,ssh host 'echo "$HOSTNAME"'
. See
http://mywiki.wooledge.org/Quotes
http://mywiki.wooledge.org/Arguments
http://wiki.bash-hackers.org/syntax/words
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments