I'm having a trouble either with a filename glob in rm
or with a variable expansion in wget
.
In Ubuntu 16.04, I did the following:
set -a
export drt="/var/www/html"
export pma="[pP][hH][pP][mM][yY][aA][dD][mM][iI][nN]"
set +a
echo $drt # Got the above.
echo $pma # Got the above.
I then ran that an executable script (~/myScripts/tp_pma.sh
):
#!/bin/bash
rm -rf ${drt}/${pma}*
wget -P ${drt} https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip
unzip ${drt}/${pma}*.zip
mv ${drt}/${pma}*/ ${drt}/phpmyadmin/
rm ${drt}/${pma}*.zip
The script succeeded partially:
- The first
rm
might have succeed or might have caused all problems below. - The
wget
succeeded partially - a zip with a fresh copy of PMA was downloaded to my home directory instead todrt
. - The
unzip
succeeded, the zip was unzipped and I got a latest phpmyadmin dir. - The
mv
failed (see error below). Because the directoryphpMyAdmin-4.7.7-all-languages
stayed in my home directory: it wasn't moved todrt
and didn't have its name changed tophpmyadmin
as I expected. - The last
rm
succeeded - the zip was deleted in my home directory.
I didn't get an error fr wget
.
Also, it seems that the value of pma
changed somehow to phpMyAdmin-4.7.7-all-languages
. I didn't change it to that value.
What is likely to have failed here and why?
wget
to write to a specific file name with-O filename.zip
and then use that name. That will get rid of that unmaintainable shell globbing pattern. But then again, you already specify the explicit name of the file at the end of the URL, so why use a shell glob in the first case? – Kusalananda Feb 11 '18 at 19:14echo $pma
only outputs the pattern because of luck. If you have a file/directory matching the pattern in the current directory, you get that name instead. – Kusalananda Feb 11 '18 at 19:17${pma}*.zip
could definitely go away. – Kusalananda Feb 11 '18 at 19:30