"This will not work if the file name contains whitespace and other special characters, because when you write $x outside quotes, the result is split into separate words (and each word is interpreted as a wildcard pattern, to boot)." . . . .