Added eval operator

This commit is contained in:
Mike Farah
2022-02-01 14:47:51 +11:00
parent 77204551ab
commit 535799462f
19 changed files with 209 additions and 30 deletions
@@ -77,6 +77,25 @@ will output
a: "12"
```
## Dynamically evaluate a path from an environment variable
The env variable can be any valid yq expression.
Given a sample.yml file of:
```yaml
a:
b:
- name: dog
- name: cat
```
then
```bash
myenv=".a.b[0].name" yq 'eval(strenv(myenv))' sample.yml
```
will output
```yaml
dog
```
## Dynamic key lookup with environment variable
Given a sample.yml file of:
```yaml