Monday, October 10, 2022

[SOLVED] Can I use shell script to read a file, find a variable in that file and store it to use in another script?

Issue

I'd like to read a yaml file and find a specific variable, then store that variable's value.

So it's something like:

- variable1:
  variable2:
    - "value"
  variable3:
  - ...

and I want to grab variable2's value, which also happens to be a file path. I'd like to be taken to that file path as well, so using the value to locate the value at that file path. Is that possible in shell script without a 3rd party library/plugin?

If not, what's the best approach to act on a yaml config with this objective?

Any help would be highly appreciated. Cheers!


Solution

Only way to parse yaml with shell could be that you need to implement your own script to parse yaml. Following is a helpful blog.

https://linuxhint.com/parse-yaml-file-bash/



Answered By - hiroyukik
Answer Checked By - Robin (WPSolving Admin)