JSON配置为bash变量

Jef*_*y04 5 bash configuration json

可能重复:
Unix命令行JSON解析器?

如果我有一个JSON配置文件和一个PHP脚本将配置文件压缩成这样的东西

database_dbname=sensei
database_password=somerandompassword
memcached_host=localhost
....
Run Code Online (Sandbox Code Playgroud)

我可以将它传递给我的bash脚本并将上面的每个条目作为变量吗?

./bin/flatten_config.php config.json | ./bin/my_bash_script.sh
Run Code Online (Sandbox Code Playgroud)

所以在我的bash脚本中我可以使用配置文件中的值

mysql -D${database_dbname} -p${database_password} ...
Run Code Online (Sandbox Code Playgroud)

don*_*nes 5

bash你可以在你的脚本文件的写入

source <(./bin/flatten_config.php config.json)
Run Code Online (Sandbox Code Playgroud)

bash将获取输出flatten_config.php并像输入一样解析它

  • +1.括号是正确的:这是[bash process substitution](http://www.gnu.org/software/bash/manual/bashref.html#Process-Substitution) (3认同)