Can using bash's globstar (**
) operator cause an out of memory error? Consider something like:
for f in /**/*; do printf '%s\n' "$f"; done
When **
is being used to generate an enormous list of files, assuming the list is too large to fit in memory, will bash crash or does it have a mechanism to handle this?
I know I've run **
on humongous numbers of files and haven't noticed a problem, so I am assuming that bash will use something like temporary files to store some of the list as it is being generated. Is that correct? Can bash's **
handle an arbitrary number of files or will it fail if the file list exceeds what can fit in memory? If it won't fail, what mechanism does it use for this? Something similar to the temp files generated by sort
?
**
-specific questions that can be asked. Do you think it isn't helpful? – terdon Mar 15 '21 at 12:45**
using the site's search function(as"**"
or\*\*
) doesn't produce any results ... and I guess if someone were searching for it, they would know the option is called "globstar" since they would need to enable it in the first place. – AdminBee Mar 15 '21 at 12:48globstar
is the (very weirdly named) option David Korn picked for enabling the recursive-globbing feature it copied from zsh over 10 years later, and bash eventually copied as well another decade later. Several shells have added zsh-style recursive-globbing support, not all with that misnamedglobstar
option. Can we make the tagrecursive-glob
instead (and maybe aglobstar
alias to it for the ksh93/bash/tcsh users?). See also The result of ls * , ls ** and ls *** – Stéphane Chazelas Mar 15 '21 at 14:06**
implemented as an iterator which is evaluated incrementally as thefor
loop progresses, or does it generate all filenames first before thefor
loop starts its evaluation? – jrw32982 Mar 17 '21 at 19:40