0

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?

EDIT: @grawity

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.

  • 1
    Can you do a for i in ./*; do declare -p i; done and for i in ./*local.php; do declare -p i; done and add the output to your post? – grawity Aug 6 at 6:00
  • I edited my question with the response. It started to work now. I don't know why. – SomeStranger314 Aug 6 at 6:20
  • 1
    My only guess would be that you were in the wrong directory when it didn't work? – grawity Aug 6 at 6:22
  • Can't be. The first mistake was done automatically by the ci. I have the wrongly created soft link to prove that the entry was correct. I am about to rerun the ci to see if it happens again. – SomeStranger314 Aug 6 at 6:24
  • You were right. It was my mistake. There was no file in the directory that had ended with local.php. Somehow I must have messed that up again in my manual tests. Now that I renamed the file, it worked as expected. To answer the question ci. Ci stands for continuous integration and it automatically deploys code to the server using ssh. In the last step of it, it runs a bash script that it has copied before to adjust a few config files and start the application it just set up. I just meant the mistake happened in automation that has worked before, therefore it wasn't the wrong directory. – SomeStranger314 Aug 6 at 7:00
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.