如果我有一个JSON配置文件和一个PHP脚本来将配置文件压缩成这样的东西
database_dbname=sensei
database_password=somerandompassword
memcached_host=localhost
....
我可以将它传递给我的bash脚本并将上面的每个条目作为变量吗?
./bin/flatten_config.php config.json | ./bin/my_bash_script.sh
这样在我的bash脚本中我可以使用配置文件中的值
mysql -D${database_dbname} -p${database_password} ...
答案 0 :(得分:5)
在bash
中,您可以在脚本文件中写入
source <(./bin/flatten_config.php config.json)
bash
将获取flatten_config.php
的输出并将其解析为输入
答案 1 :(得分:3)
结帐TickTick。
这是一个真正的Bash JSON解析器。
#!/bin/bash
. /path/to/ticktick.sh
# File
DATA=`cat data.json`
# cURL
#DATA=`curl http://foobar3000.com/echo/request.json`
tickParse "$DATA"
echo ``pathname``
echo ``headers["user-agent"]``