I need to expand a glob pattern (like ../smth*/*
, or /etc/cron*/
) into a list of files, programmatically. What would be the best way to do it?
Bash Wildcards – Best Way to Expand Glob Pattern
bashwildcards
bashwildcards
I need to expand a glob pattern (like ../smth*/*
, or /etc/cron*/
) into a list of files, programmatically. What would be the best way to do it?
Best Answer
Just let it expand inside an array declaration's right side:
Note that the shell option
nullglob
needs to be set.It is not set by default.
It prevents an error in case the glob (or one of multiple globs) does not match any name.
Set it in
bash
withor in
zsh
with