1
2

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 5 years have passed since last update.

Bashで使えるMustache実装のmoが便利

1
Last updated at Posted at 2017-08-18

Mo

大げさなものは必要ないが、ちょっとしたテンプレート処理をスクリプトで実行したい場面はたまにあると思います。でも、その環境に何かをインストールさせるのはちょっと…というときには、Bashのみで完結すると嬉しいです。

そこで、MustacheテンプレートのBash実装であるmoを使ってみました。

適当なテンプレートを用意します。

foo.yml.mo
foo:
  {{FOO}}

出力するための数行のスクリプトを用意します。

generate.sh
# !/usr/bin/env bash
export FOO='hello world'
MO="$(curl -sf https://raw.githubusercontent.com/tests-always-included/mo/master/mo)"
cat foo.yml.mo | bash -c "${MO}"
$ ./generate.sh
foo:
  hello world

カジュアルに使えそうで便利です。

または

envsubstというコマンドがある。こちらも軽量で良い。

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?