appensinding multiline variable to file bash

Js doee

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,

Gilles Quenot

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Bash Perl multiline match into variable

From Dev

Echo multiline string into file bash

From Dev

Output fdisk bash command to multiline variable

From Dev

how to redirect multiline bash command into a variable

From Dev

How to write a multiline string to a file in Bash

From Dev

bash replace multiline text in file, with pattern

From Dev

sed - calling a variable from a file with multiline

From Dev

Simple "Variable" Bash File

From Dev

How to convert multiline file into a string in bash with newline character?

From Dev

Set variable from awk while parsing lines from a multiline file

From Dev

Replace a variable with the name of the file in Bash

From Dev

Comparing variable with File names bash

From Dev

Bash: Update a variable within a file

From Dev

Bash .sh file variable scope

From Dev

sqlcmd in bash file - store to variable

From Dev

Assigning a path as a variable in bash file

From Dev

Using a variable as a file name and writing to the file in bash

From Dev

Missing File In Bash - Create a file and assign it to a variable

From Dev

Print a multiline variable in a column

From Dev

Bash and awk - how to pass a variable to awk when doing multiline pattern maths?

From Dev

Bash 'unbound variable' error when variables are referenced in multiline comment (set -u)

From Dev

Bash and awk - how to pass a variable to awk when doing multiline pattern maths?

From Dev

PHP Write to file multiline

From Dev

Regex for multiline .ini file

From Dev

Variable substitution to get the file name and extension in bash

From Dev

Bash Script Properties File Using '.' in Variable Name

From Dev

How to pass a bash variable into an sql file

From Dev

Read a Bash variable assignment from other file

From Dev

Pass variable from applescript to executable bash file

Related Related

  1. 1

    Bash Perl multiline match into variable

  2. 2

    Echo multiline string into file bash

  3. 3

    Output fdisk bash command to multiline variable

  4. 4

    how to redirect multiline bash command into a variable

  5. 5

    How to write a multiline string to a file in Bash

  6. 6

    bash replace multiline text in file, with pattern

  7. 7

    sed - calling a variable from a file with multiline

  8. 8

    Simple "Variable" Bash File

  9. 9

    How to convert multiline file into a string in bash with newline character?

  10. 10

    Set variable from awk while parsing lines from a multiline file

  11. 11

    Replace a variable with the name of the file in Bash

  12. 12

    Comparing variable with File names bash

  13. 13

    Bash: Update a variable within a file

  14. 14

    Bash .sh file variable scope

  15. 15

    sqlcmd in bash file - store to variable

  16. 16

    Assigning a path as a variable in bash file

  17. 17

    Using a variable as a file name and writing to the file in bash

  18. 18

    Missing File In Bash - Create a file and assign it to a variable

  19. 19

    Print a multiline variable in a column

  20. 20

    Bash and awk - how to pass a variable to awk when doing multiline pattern maths?

  21. 21

    Bash 'unbound variable' error when variables are referenced in multiline comment (set -u)

  22. 22

    Bash and awk - how to pass a variable to awk when doing multiline pattern maths?

  23. 23

    PHP Write to file multiline

  24. 24

    Regex for multiline .ini file

  25. 25

    Variable substitution to get the file name and extension in bash

  26. 26

    Bash Script Properties File Using '.' in Variable Name

  27. 27

    How to pass a bash variable into an sql file

  28. 28

    Read a Bash variable assignment from other file

  29. 29

    Pass variable from applescript to executable bash file

HotTag

Archive