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:

varName=fileFormat:filePath

$ echo 'message: Hello world' > test.yaml
$ go run cmd/dasel/main.go -o json testVar=yaml: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