I am trying to debug why a script didn't do what I wanted on my server. And while testing I found a curiosity. I have a directory that looks roughly like this:
bash-4.3# ls -l ./ total 0 -rw-r--r-- 1 root root 0 Aug 6 05:46 db.local.php -rw-r--r-- 1 root root 0 Aug 6 05:46 global.php -rw-r--r-- 1 root root 0 Aug 6 05:46 local.php -rw-r--r-- 1 root root 0 Aug 6 05:46 someOther.global.php
Look at running this command, the output is exactly what I expected:
bash-4.3# for i in ./*; do echo $i; done ./db.local.php ./global.php ./local.php ./someOther.global.php
But when I run this command the output doesn't make sense. For some reason the asterisk is escaped:
bash-4.3# for i in ./*local.php; do echo $i; done *local.php
This happens on one server with bash 4.3.30 installed. I tried to recreate the same behaviour locally in bash 4.4 and in a docker container bash:4.3 (which is bash 4.3.48), but I couldn't recreate the issue.
Is there any setting that could account for it? Anything chance that is not just a bug?
Small addendum I just figured out before sending this off: If I start the same docker container on the server, it behaves the same way, making it extremely unlike to be a settings issue, since nothing from the host system was mounted in the container. Still, I am not sure what it could be, so has anyone any idea?
bash-4.3$ for i in ./*; do declare -p i; done declare -- i="./db.local.php" declare -- i="./global.php" declare -- i="./local.php" declare -- i="./someOther.global.php" bash-4.3$ for i in ./*local.php; do declare -p i; done declare -- i="./db.local.php" declare -- i="./local.php" bash-4.3$ for i in ./*; do echo $i; done ./db.local.php ./global.php ./local.php ./someOther.global.php bash-4.3$ for i in ./*local.php; do echo $i; done ./db.local.php ./local.php
I don't understand it. after declaring it, it started to work normally. It also works normally with other files that have other endings. I don't understand what just happened.
SOLUTION: Thanks to grawity for his help. I made some mistakes in my testing above apparently. It looks like the behaviour above is the standard behaviour when there is no file fulfilling the asterisk completion.