0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

yamlの値をシェルで使いたい

Posted at

シェルスクリプト内でyamlのデータを使いたかった時にちょっと詰まったので共有します。

概要

色々解決手法はあると思いますが、以下の方法で解決しました。
yamljsonjqで取得

シェル

use_yaml.sh
# !/bin/bash
python json_gen.py > hoge.json
FUGA=`jq ".path.to.fuga" hoge.json`

pythonymlからjsonに変換して、jqで取得して使用しました。
実際にはyamlのファイル名をpythonに渡してそれをjsonに変換しました。

python

json_gen.py
import yaml, json

with open('./path/to/yml/hoge.yml') as file:
    obj = yaml.safe_load(file)
    js = json.dumps(obj, indent=2)
    print(js)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?