如何在 shell 脚本中获取 INI 值? [英] How do I grab an INI value within a shell script?

查看:39
本文介绍了如何在 shell 脚本中获取 INI 值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个parameters.ini文件,比如:

I have a parameters.ini file, such as:

[parameters.ini]
    database_user    = user
    database_version = 20110611142248

我想从 bash shell 脚本中读入并使用 parameters.ini 文件中指定的数据库版本,以便我可以处理它.

I want to read in and use the database version specified in the parameters.ini file from within a bash shell script so I can process it.

#!/bin/sh    
# Need to get database version from parameters.ini file to use in script    
php app/console doctrine:migrations:migrate $DATABASE_VERSION

我该怎么做?

推荐答案

如何使用 awk 来 grepping 那行

How about grepping for that line then using awk

version=$(awk -F "=" '/database_version/ {print $2}' parameters.ini)

这篇关于如何在 shell 脚本中获取 INI 值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆