On Tue, Mar 21, 2023 at 5:26 PM alex xmb ratchev <fxmb...@gmail.com> wrote: > On Tue, Mar 21, 2023, 21:05 Grisha Levit <grishale...@gmail.com> wrote: >> >> compgen -G 'foo/*' >/dev/null && COMPREPLY=(bar) > > i dont get that code at all , but i like idea of speedier file filling .. can > u explain some in short ?
Let's say you want to know if there are any entries starting with `foo' in the current directory. You can do: GLOBIGNORE= shopt -s nullglob set +o noglob tmp=(foo*) if (( ${#tmp[@]} )); then ... Or you can do if compgen -G 'foo*' >/dev/null; then ... The latter doesn't care about nullglob / noglob / GLOBIGNORE and if the number of files is large can be a lot faster. P.S. If you are interested in files that may or may not start with a dot, you do need to set dotglob in either case, which was the motivation for https://lists.gnu.org/archive/html/bug-bash/2023-03/msg00062.html