mirror of
https://github.com/NixOS/nix.git
synced 2024-11-22 14:52:55 +00:00
string interpolation escape example (#10966)
* string interpolation escape example Make it easier to find the documentation, and the example might be enough for most cases. Co-authored-by: Robert Hensing <roberth@users.noreply.github.com> Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
This commit is contained in:
parent
aff0fbc764
commit
3b388f6629
@ -43,6 +43,47 @@ configureFlags = "
|
||||
Note that Nix expressions and strings can be arbitrarily nested;
|
||||
in this case the outer string contains various interpolated expressions that themselves contain strings (e.g., `"-thread"`), some of which in turn contain interpolated expressions (e.g., `${mesa}`).
|
||||
|
||||
To write a literal `${` in an regular string, escape it with a backslash (`\`).
|
||||
|
||||
> **Example**
|
||||
>
|
||||
> ```nix
|
||||
> "echo \${PATH}"
|
||||
> ```
|
||||
>
|
||||
> "echo ${PATH}"
|
||||
|
||||
To write a literal `${` in an indented string, escape it with two single quotes (`''`).
|
||||
|
||||
> **Example**
|
||||
>
|
||||
> ```nix
|
||||
> ''
|
||||
> echo ''${PATH}
|
||||
> ''
|
||||
> ```
|
||||
>
|
||||
> "echo ${PATH}\n"
|
||||
|
||||
`$${` can be written literally in any string.
|
||||
|
||||
> **Example**
|
||||
>
|
||||
> In Make, `$` in file names or recipes is represented as `$$`, see [GNU `make`: Basics of Variable Reference](https://www.gnu.org/software/make/manual/html_node/Reference.html#Basics-of-Variable-References).
|
||||
> This can be expressed directly in the Nix language strings:
|
||||
>
|
||||
> ```nix
|
||||
> ''
|
||||
> MAKEVAR = Hello
|
||||
> all:
|
||||
> @export BASHVAR=world; echo $(MAKEVAR) $${BASHVAR}
|
||||
> ''
|
||||
> ```
|
||||
>
|
||||
> "MAKEVAR = Hello\nall:\n\t@export BASHVAR=world; echo $(MAKEVAR) $\${BASHVAR}\n"
|
||||
|
||||
See the [documentation on strings][string] for details.
|
||||
|
||||
### Path
|
||||
|
||||
Rather than writing
|
||||
|
Loading…
Reference in New Issue
Block a user