Preparation
$ mkdir globbing
$ cd globbing
$ mkdir -p folder/{sub,another}folder/content/deepfolder/
touch macy stacy tracy "file with space" folder/{sub,another}folder/content/deepfolder/file .hiddenfile
$ shopt -u nullglob
$ shopt -u failglob
$ shopt -u dotglob
$ shopt -u nocaseglob
$ shopt -u extglob
$ shopt -u globstar
In case the glob does not match anything the result is determined by the
options nullglob
and failglob
. If neither of them are set, Bash will return the glob itself if nothing is matched
$ echo no*match
no*match
If nullglob
is activated then nothing (null
) is returned:
$ shopt -s nullglob
$ echo no*match
$
If failglob
is activated then an error message is returned:
$ shopt -s failglob
$ echo no*match
bash: no match: no*match
$
Notice, that the failglob
option supersedes the nullglob
option, i.e.,
if nullglob
and failglob
are both set, then - in case of no match - an
error is returned.