Protect '[...]' from shell
The '[a-z]' construction must be passed as-is to grep. If not protected, the shell can interpret it (looking for files with one character).
$ touch b c $ ls b c $ echo [a-z] b c $ echo '[a-z]' [a-z] $ ls | grep [a-z] # looks for 'b' in file 'c', finds nothing, but no error as c is a existing file $ ls | grep '[a-z]' b c $ rm b c $ echo [a-z] [a-z]
Last one: nothing matches, the shell keeps the whole pattern (as with '*') => current code works sometimes