bash-yaml

Bash-YAML is a simple YAML parser written in Bash script.

MIT License

Stars
3

Bash-YAML

Bash-YAML is a simple YAML parser.

Installation

Manually

git clone https://github.com/ArtBIT/bash-yaml.git
source path/to/bash-yaml/src/yaml

Using bash-clam

clam install ArtBIT/bash-yaml --source src/yaml

Usage

Example 1: Get yaml value

# (Contents of example1.yml)
# | some:
# |   deeply:
# |     nested:
# |       option: 1
#

cat example1.yml | yaml_get_value some.deeply.nested.option
# Outputs 1

Example 2: convert yaml to bash variables

# (Contents of example2.yml)
# | app:
# |   settings:
# |     title: My Awesome App
# |     color: #DADADA
# |     language: en
#

eval "$(cat example2.yml | yaml_parse app.settings)"
# Defines the following bash variables
# app_settings=""
# app_settings_title="My Awesome App"
# app_settings_color="#DADADA"
# app_settings_language="en"

eval "$(cat example.yml | yaml_parse app.settings --prefix noconflict)"
# Defines the following bash variables
# noconflict_app_settings=""
# noconflict_app_settings_title="My Awesome App"
# noconflict_app_settings_color="#DADADA"
# noconflict_app_settings_language="en"

Example 3: replace yaml values

# (Contents of example3.yml)
# | app:
# |   settings:
# |     title: My Awesome App
# |     color: #DADADA
# |     language: en
#

cat example3.yml | 
  yaml_replace app.settings.color "#FFF" |
  yaml_replace app.settings.language "rs" |
  yaml_replace app.settings.title "My Other App"

# Will output: 
app:
  settings:
    title: My Other App
    color: #FFF
    language: rs

# The source file is not automatically updated, if you
# want to update the original filename, please use 
# `sponge` to wait for the stdin to dry-out 
# before writing to original file, to avoid race conditions.
cat example3.yml | 
  yaml_replace app.settings.color "#FFF" |
  yaml_replace app.settings.language "rs" |
  yaml_replace app.settings.title "My Other App" |
  sponge example3.yml

License

MIT

Badges
Extracted from project README
Build Status GitHub license GitHub stars awesomeness