Today I encountered this:

$ echo $'foo\\n'
$ echo 'foo\\n'

I have never come across this before and never heard anyone mention this. I would've expected $ outside of strings to cause that string to be treated as a variable name. Where is this documented and has it always been this way?

  • 2
    Tip: To find this in your system's built-in bash(1) man page, type man bash and then type /\$\' to search for the literal string $'.
    – Spiff
    Dec 24 '20 at 2:59

This is bash's ANSI-C Quoting

Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows:

It's documented here https://www.gnu.org/software/bash/manual/bash.html#ANSI_002dC-Quoting

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.