BTW -- while it's unrelated to the question (follow the duplicate link for that), don't ever use `ls` for this job. `shopt -s nullglob; files=( * )` is far more reliable; see [Why you shouldn't parse the output of `ls`](http://mywiki.wooledge.org/ParsingLs) and [BashPitfalls #1](http://mywiki.wooledge.org/BashPitfalls#for_i_in_.24.28ls_.2A.mp3.29).
– Charles DuffyJan 06 '18 at 19:09
@CharlesDuffy: I basically agree, but shouldn't it be `shopt=$(shopt -p nullglob); shopt -s nullglob; files=( * ); $shopt`? Especially longer scripts are difficult to maintain, if shell options are changed somewhere in the middle; plus, it could be that the script has already been invoked with a "non-standard" shell option setting.
– user1934428Jan 08 '18 at 10:32
1
@user1934428, *nod* -- though I'd tend to argue that it makes sense to write the entire script with a specific value for `nullglob` in mind, and thus set it once at the beginning. If that desired value is unset, then `files=( * ); [[ -e ${files[0]} || -L ${files[0]} ]] || files=( )` is a bit more verbose, but will do the job.
– Charles DuffyJan 08 '18 at 16:22