Variables

Dasel allows you to define variables for use in your other selectors.

Variables are referenced using a $ prefix.

Note that these variables are essentially globals, and once defined, they are accessible at any point in the execution.

Variables can be used alongside stdin.

From the CLI

You can set variables from the CLI by passing additional arguments in the form of:

--var name=format:content

If you wish to pass a file as a variable you can use:

--var name=format:file:filepath

$ echo 'message: Hello world' > test.yaml
$ dasel -o json testVar=yaml:file:test.yaml '$testVar.message'
"Hello world"

Note that at this time variables from the CLI are currently required to be documents read from the file system. There are plans to change this in the future.

Standard variables

Some variables are provided by dasel and will always exist:

  • $this - The current element

  • $root - The root document passed through stdin.

Last updated