F:>ruby -e “puts %q[\a\b\c]”
-e:1: unterminated string meets end of file
F:>
It seems to me the last \ shouldn’t need to be escaped as \, though that
does work. What’s up?
%q[foo] is equivalent to the single-quoted string literal ‘foo’. In
the same way, the only escapable characters are backslash and the
character that ends the literal:
‘Mark's string’
%q[square (]) bracket]
A literal backslash in a single quoted string only needs to be escaped
where it might be confused as escaping the final quoting character,
like in your example.
In a quoted string, a \cx is an escape for ctrl-x, so the \c] is
interpreted as ctrl-] as the ] is an escape for the bracket in the
quoted
string. Since there is no close bracket you get an error.