In bash, if you do this:
mkdir /tmp/empty
array=(/tmp/empty/*)
you find that array
now has one element, \"/tmp/empty/*\"
This may be close to what you want; as is, it requires executing a command to expand the glob.
$ ls
file1 file2
$ array=( $(shopt -s nullglob; ls foo*) )
$ ls foo*
ls: foo*: No such file or directory
$ echo ${array[*]}
file1 file2
Instead of setting array
in the subshell, we create a subshell using $()
whose output is captured by array
.