read yaml files in bash
function yaml() {
hashdot=$(gem list hash_dot);
if ! [ "$hashdot" != "" ]; then sudo gem install "hash_dot" ; fi
if [ -f $1 ];then
cmd=" Hash.use_dot_syntax = true; hash = YAML.load(File.read('$1'));";
if [ "$2" != "" ] ;then
cmd="$cmd puts hash.$2;"
else
cmd="$cmd puts hash;"
fi
ruby -r yaml -r hash_dot <<< $cmd;
fi
}
samle yaml content
mykey:
myotherkey: test
how to use
$ config=$(yaml config.yml mykey.myotherkey)
output
$ echo $config
$ test
Written by hvlmnns
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#