GNU/Linux

LINUX NOTES SECTION

May 1, 2025

Subsections of GNU/Linux

Bash yaml parser

yb - a bash yaml parser

yb provides a pure Bash solution to YAML parsing.

Usage

yb [-h|-a|-c|-q|-r|-A-C-d-F-K-l-L-R-n-T] [-f <file>|-o <object>] [-k <key>] [-v <value>|-O <object value>]

Examples

./yb -f file.yaml -k "key.childkey"

From the repository, you can do a quick try like so:

./yb -f tests/user.yaml -k "yb"

Create keys:

./yb -af tests/user.yaml -k "new.key"

add an inline-value:

./yb -af tests/user.yaml -k "new.key" -v "one, two"

change it:

./yb -cf tests/user.yaml -k "new.key" -v "three"

add list-values:

./yb -af tests/user.yaml -k "new.- list" -v "- one - two"

add an ASCII within a pipe-key:

./yb -af tests/user.yaml -k "new.ascii|" -v "|>  ___  _ |>  \  \// |>   \  / |>   / / |>  /_/"

manipulate the YAML as a bash variable:

# using the '-R' raw option is advised to retrieve the content without color codes
my_YAML=$(./yb -f tests/user.yaml -k "new")
my_YAML=$(./yb -ao "${my_YAML}" -k "in_memory" -v "true")

add it to a file:

./yb -af tests/user.yaml -k "new.copy" -o "${my_YAML}"

Remove one value:

./yb -rf tests/user.yaml -k "new.- list" -v "- one"

or remove everything:

./yb -rf tests/user.yaml -k "new"

Options

yb options are divided under 3 types:

  • action: action options are ran against the file and are not compatible with each others. They are compatible with input, but not format.
  • input: input options are user settable options, and are compatible with each others. They are compatible with both action and format.
  • format: format options print the output in various ways. They are compatible with each others, with the input type , but not the action one.
OptionNameTypeDescriptionExampleNotes
-aaddactionAdds key(s), value(s) or both.yb -f "file.yaml" -a -k "key" -v "value"
-cchangeactionChanges value(s).yb -f "file.yaml" -c -k "key" -v "new_value"
-qqueryactionPrints true or false if key(s), value(s) or both are present or not.yb -f "file.yaml" -q -k "key"Using single quotes is advised to retrieve a pipe value -v 'pipe value'.
-rremoveactionRemoves key(s), value(s) or both.yb -f "file.yaml" -r -k "key" -v "value"Using single quotes is advised to remove a pipe value -v 'pipe value'.
-ffileinputYAML file path.yb -f "file.yaml"A file can be presented without the -f option, as the $1 option. -f and -c are not compatible with each others.
-oobjectinputYAML object.yb -o "${YAML_object}"YAML object can be used with all actions. -f and -o are compatible together, only when adding an object to a file.
-Oobject valueinputYAML object value.yb -f "file.yaml" -O "${YAML_object}"YAML object can be used with the -a action.
-kkeyinputKey(s) selection path.yb -f "file.yaml" -k "key"Support keys in this format :key, key.childkey, - list-key, pipe-key|. Multiple key(s) can be provided with a . as the separator.
-vvalueinputValue(s) to be added, removed, queried or changed.yb -f "file.yaml" -k "key" -v "value"Support values in this format : value, - list-value, |> pipe-value.
-AarrayformatPrints the output as a bash array.yb -f "file.yaml" -A -k "key"Will provide a different formatting if used with -F or -d.
-CcolorsformatForce colors in a non-terminal output.yb -Cf "file.yaml" -A -k "key"
-ddepthformatProvides the output with the original depth.yb -f "file.yaml" -d -k "key.childkey" -v "new_value"
-FformatformatPrints a formatted output to represent the arborescence inline.yb -f "file.yaml" -F -k "key"Will provide a different formatting if used with -A or -d.
-Kkeys-onlyformatPrints only keys.yb -Kf "file.yaml" -k "key"
-llineformatPrints { {line } } on each lines.yb -f "file.yaml" -l -k "key"
-LlevelformatPrints { {<level number> } } on each lines.yb -f "file.yaml" -L -k "key"
-RrawformatPrints the ouptut without added colors, comments and empty lines.yb -f "file.yaml" -R -k "key"
-nnumberformatPrints { {<line number> } } on each lines.yb -f "file.yaml" -n -k "key"
-TtypeformatPrints a value type.yb -f "file.yaml" -T -k "key"Supports null, boolean, integer, floating number, string.
-sspacesDeprecatedSpaces number selection.

YAML support

yb provides the basic YAML support for editing and reading a YAML file. As by version 0.9, yb doesn’t support advanced features such as group based search, anchors, aliases, and overrides.

Thank you

All of you, YAML’ers !

Made in Bash.