mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-25 23:36:16 +02: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
1 changed files with 41 additions and 0 deletions
|
@ -43,6 +43,47 @@ configureFlags = "
|
||||||
Note that Nix expressions and strings can be arbitrarily nested;
|
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}`).
|
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
|
### Path
|
||||||
|
|
||||||
Rather than writing
|
Rather than writing
|
||||||
|
|
Loading…
Reference in a new issue