From 952380f6d739ccbb7d3afdbc5326c8100de4ce1c Mon Sep 17 00:00:00 2001 From: Fred Date: Wed, 7 Feb 2024 12:36:25 +0000 Subject: [PATCH] doc: add information about windows path in variables --- docs/content/configuration/variables/index.md | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/docs/content/configuration/variables/index.md b/docs/content/configuration/variables/index.md index a2f74cd7..703b7c6e 100644 --- a/docs/content/configuration/variables/index.md +++ b/docs/content/configuration/variables/index.md @@ -349,13 +349,17 @@ profile src: As you can see, the `src` profile inherited from the `generic` profile. The tags `{{ .Profile.Name }}` got replaced by the name of the current profile `src`. Now you can reuse the same generic configuration in another profile. -You might have noticed the `read-data-subset` in the `check` section which will read a seventh of the data every day, meaning the whole repository data will be -checked over a week. You can find [more information about this trick](https://stackoverflow.com/a/72465098). +You might have noticed the `read-data-subset` in the `check` section which will read a seventh of the data every day, meaning the whole repository data will be checked over a week. You can find [more information about this trick](https://stackoverflow.com/a/72465098). ### Hand-made variables -But you can also define variables yourself. Hand-made variables starts with a `$` ([PHP](https://en.wikipedia.org/wiki/PHP) anyone?) and get declared and -assigned with the `:=` operator ([Pascal](https://en.wikipedia.org/wiki/Pascal_(programming_language)) anyone?). Here's an example: +You can also define variables yourself. Hand-made variables starts with a `$` ([PHP](https://en.wikipedia.org/wiki/PHP) anyone?) and get declared and assigned with the `:=` operator ([Pascal](https://en.wikipedia.org/wiki/Pascal_(programming_language)) anyone?). + +{{% notice style="info" %}} +You can only use double quotes `"` to declare the string, single quotes `'` are not allowed. You can also use backticks to declare the string. +{{% /notice %}} + +Here's an example: ```yaml # declare and assign a value to the variable @@ -369,6 +373,34 @@ profile: Variables are only valid in the file they are declared in. They cannot be shared in files loaded via `include`. {{% /notice %}} +Variables can be redefined using the `=` operator. The new value will be used from the point of redefinition to the end of the file. + +```yaml +# declare and assign a value to the variable +{{ $name := "something" }} + +# reassign a new value to the variable +{{ $name = "something else" }} + +``` + +#### Windows path inside a variable + +Windows path are using backslashes `\` and are interpreted as escape characters in the configuration file. To use a Windows path inside a variable, you have a few options: +- you can escape the backslashes with another backslash. +- you can use forward slashes `/` instead of backslashes. Windows is able to use forward slashes in paths. +- you can use the backtick to declare the string instead of a double quote. + +For example: +```yaml +# double backslash +{{ $path := "C:\\Users\\CP\\Documents" }} +# forward slash +{{ $path := "C:/Users/CP/Documents" }} +# backticks +{{ $path := `C:\Users\CP\Documents` }} +``` + #### Example Here's an example of a configuration on Linux where I use a variable `$mountpoint` set to a USB drive mount point: