bash - if file exist

Custom / CUSTOM
March 22, 2010 at 05:51:50
Specs: linux red hat, 2.401 GHz / 2047 MB
I had a w1f moment ... why does bash does not do what it should here ?

[root@vegas pbin]# if [ -f x??? ]
> then
> echo d
> fi
bash: [: too many arguments
[root@vegas pbin]#

See More: bash - if file exist

Report •

March 22, 2010 at 07:19:27
Not sure; works on mine.
/home/bladeeg$ if [ -f .prof??? ]; then echo Y; fi

Report •

March 22, 2010 at 09:21:31
I can only reproduce on one Linux, the other one reacts normally. Both are Red Hats, both use Bash as shell ... Versions of Red Hat are slightly different though.

edit: Issue is reported a lot, but no obvious solution to it. It just needs to work, end of the line. There's no reason it shouldn't, apart from a bug or a failed Linux installation.

edit2: As I sort of thought, it's the same bug as the one you can get from LS commands and such, when you have too many (or too large) files being queried. It may be related to Trash as well. If I do this :

if [ -f xg* ]; then; echo f; fi

This command does not show any error (but also no output). I do not have any file named xg* in that directory. So, all OK.

... But, when I do this:

if [ -f x* ]; then; echo f; fi

It shows the error, and stops. I currently have files named x* in them, which are pretty big. I also HAD other files named like that, but they are gone (and from Trash as well). And that were a lot of them, no big, but a lot. The ones remaining are not a lot, but big. So, no problem with this or that Linux, it's a File System querying issue.

Report •

Related Solutions

Ask Question