V
V
Viktor Taran2021-03-15 03:53:28
PHP
Viktor Taran, 2021-03-15 03:53:28

How to solve the shielding problem?

I am writing a script on the bash, but the choice of variables from the config has to be done in PHP
and everything is great up to the place where I cram the variable

We declare everything there

#!/bin/sh
SITEDIR="/home/bitrix/ext_www"                     
DBCONN="bitrix/php_interface/dbconn.php"            
TMPDIR="/var/backup/site"       
.....


works
DBPASS=$(/bin/php -r 'include "/home/bitrix/ext_www/site.ru/bitrix/php_interface/dbconn.php"; echo "$DBPassword";')


does not work
DBPASS=$(/bin/php -r 'include "$SITEDIR/$ELEMENT/$DBCONN"; echo "$DBPassword";')


Because variables remain TEXT
OUTPUT /bin/php -r 'include "$SITEDIR/$ELEMENT/$DBCONN"; echo "$DBPassword";
It is connected with ' 'how much I understand and what to do?
I can’t replace them with double ones, PHP doesn’t work,
screening doesn’t help either.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nokimaro, 2021-03-15
@nokimaro

DBPASS=$(/bin/php -r "include '$SITEDIR/$ELEMENT/$WEB/$DBCONN'; echo \$DBPassword;")

Use double quotes
bash variables inside an expression will go like $VARa PHP variables with a backslash before $ -\$DBPassword

A
AUser0, 2021-03-15
@AUser0

Where does PHP get all these values ​​from? Where and when were they defined?
Well, so they must be assigned directly in this inline script, BEFORE using it.
Check via:/bin/php -r 'var_dump($SITEDIR);'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question