Question
Variable substitution fails for exported variable
While in my home directory, I ran export drt="/var/www/html"
. I then sourced a script (script 1) that in between other commands, also sources another script (script 2):
#!/bin/bash
find ${drt}/ -type f -iname "*phpmyadmin*" -exec rm -rf {} \;
wget -P ${drt}/ https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip
As you can see, the desired state is to download phpmyadmin to the value of drt
, which is of course /var/www/html
, but instead being downloaded to /var/www/html
, it was downloaded to my home directory.
Not only I sourced every script, I exported the variable to have full scope possible just in case, but it seems not to be enough and the ${drt}
variable substitution fails.
- I tried to debug with
set -x
at the base of the script, but I got no enlighting output. - To source a file I use the command
source myFile
, not any other syntax.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×