I read that it is a best practice to double quote all of your variable expansions in Bash. I also read that one cannot use a shell glob (wildcard(*
)) right after a double quoted variable expansion. These situations conflict when one wants use the value of a regex pattern, expanded out of a variable.
The reason I would sometimes want to combine regex with a wildcard is to keep my regex minimal, neater, in my personal taste.
My particular problem
I downloaded phpmyadmin into my document root directory and unzipped it, but I fail to rename it with mv
by a regex pattern I put in a variable, and available when expanding its variable. Here's the exact trace:
userName@compName:/var/www/html# ll
total 11336
drwxr-xr-x 3 root root 4096 Feb 14 07:04 ./
drwxr-xr-x 3 root root 4096 Feb 14 06:56 ../
-rw-r--r-- 1 root root 612 Feb 14 06:57 index.nginx-debian.html
drwxr-xr-x 12 root root 4096 Dec 23 08:50 phpMyAdmin-4.7.7-all-languages/
-rw-r--r-- 1 root root 11589684 Dec 23 14:08 phpMyAdmin-latest-all-languages.zip
userName@compName:/var/www/html# echo $pma
[pP][hH][pP][mM][yY][aA][dD][mM][iI][nN]
userName@compName:/var/www/html# mv "$pma"*/ phpmyadmin/
mv: cannot stat '[pP][hH][pP][mM][yY][aA][dD][mM][iI][nN]*/': No such file or directory
If I'll unquote the variable expansion to ${pma}
I would indeed be able to combine the variable expansion and the regex, as in ${pma}*
, but it is important to me to follow the best practice without exceptions, if I can.
My question
How could I keep the variable expansion double quoted, but still using the extracted value with a wildcard?
phpMyAdmin
part of the filename will ever change any letters for upper to lower case or vice-versa. – cas Feb 14 '18 at 08:25index.nginx-debian.html
filename), why not just use the phpmyadmin package in debian? Essential reading: https://wiki.debian.org/DontBreakDebian – cas Feb 14 '18 at 08:30/usr/share/
and I then have to create a symlink from document root to/usr/share/
that by itself could change any day to some other location, so I prefer to download phpmyadmin directly to document root and be done with it. – Arcticooling Feb 14 '18 at 08:35/var/www/
changed to/var/www/html
, wasn't? – Arcticooling Feb 14 '18 at 08:53mv ${pma}* / phpmyadmin/
didn't do the job ? – Archemar Feb 14 '18 at 14:43wildcards
tag wiki, … (Cont’d) – Scott - Слава Україні Feb 18 '18 at 21:18