Everything has probably actually worked as you expected, but you have been misled by two different phenomena:
ls
and some other utilities display ?
for non-printable characters by default
?
is a glob that matches a single character
That results in the following behaviour:
$ echo foo > $'\007'
$ ls
?
$ cat ?
foo
So it seems like we have a file that is literally named ?
, right? Actually, that's just a happy coincidence of the two above phenomena -- the file is still called ^G
:
$ printf '<%q>\n' *
<$'\a'>
$ ls -lb
total 0
-rw-r--r-- 1 chris chris 0 Aug 1 14:20 \a
Probably everything worked as you expected, despite what immediately appeared to indicate that the file was literally called ?
.