Escaping in Nix's indented strings

I have a bash script where I need to have the syntax like this:

echo "First value is '${ARRAY[0]}'."

How to I put this into Nix’s indented string? I can’t find a way to escape the sequence '${.

Any advice? I can insert an empty antiquotation ${""} between ' and $, but it’s verbose, and I will still need to escape ${.

2 Likes

You can escape ${ with ''${ and subsequently you can use ''\X (replacing X by some character) for inserting a verbatim character, which is necessary because you have a ' before the ${:

''
  echo "First value is ''\'''${ARRAY[0]}'."
''

Yes, I know it looks a bit ugly, but you could still use ${"..."} instead to prevent all those single quotes, for example:

''
  echo "${"First value is '\${ARRAY[0]}'"}"
''
6 Likes

Ah, right, I overlooked this part of the documentation:

''\ escapes any other character.

Thank you.

And put what inside the quotes?..
EDIT: I see the update, yes, this looks better.