[Nix-dev] Escape ${ in multiline string

jeaye contact at jeaye.com
Tue Dec 29 05:21:44 CET 2015


On Tue, Dec 29, 2015 at 12:05:23PM +0000, 4levels wrote:
>    Hi Nix Devs,
>    I'm currently struggling to create a bash script within a nix multiline
>    string, terminted by double single quotes.
>    In the bash script, I need to put ${} statements but this is throwing
>    compile errors (Undefined variable error).  I've tried escaping the $ sign
>    with a backslash, but that doesn't help.  I also tried escaping with a
>    double backslash, same result.
>    Any ideas? Should I rewrite the bash script to not use the ${ statements?
>    Kind regards,
>    code example
>          s3Backup = name:
>          ''
>            ...
>            DAILYLOGFILE="/var/log/duplicity/backup.log"
>            ...
>            # Clear the old daily log file
>            cat /dev/null > ${DAILYLOGFILE}  // -> compile error: undefined
>    variable DAILYLOGFILE
>            ...
>          '';
>    Erik aka 4levels

The trick is to put another double single quote pair before the ${FOO}.
So ${DAILYLOGFILE} should be ''${DAILYLOGFILE}.


More information about the nix-dev mailing list