I don't understand why * returns itself when there's no match. This answer states that this is the case, but I don't understand the rationale for this behaviour. Why doesn't *, or any generic pattern, just return an empty string in case of no match?
$ls # Look, no files
$touch a # Add a file
$echo * # Works as expected
a
$rm a # Remove the file
$echo * # Will output a '*'. Why not ''?
*
$* # Ok, * will fail, but how come the previous output?
-bash: *: command not found
$
If no matching filenames are found, and the shell option nullglob is disabled, the word is left unchanged
; see also:echo ?
– Jeff Schaller Nov 01 '16 at 17:42