Giter VIP home page Giter VIP logo

config-parser's Introduction

config-parser

Configuration (ini style) parser in Bash

About

This script is freely inspired by bash ini parser from ajdiaz. It's a fast way to parse an ini-style configuration file and to load the variables in your main script.

License

This script is under the MIT License. See LICENSE file.

Dependencies

config-parser.sh uses sed to parse the ini file.

Issues have been found with Mac OSX' sed command (see Issue #4), but sukima was kind enough to fork this project and make a OSX version of the script: here.

Usage

Just include config-parser.sh in your code, and then call it:

# parse the configuration file
config_parser "/path/to/config/file.ini";
# load <my_section> from the ini file
config.section.<my_section>;

INI File example

[dev]
foo="bar";
foofoo="foo";
foofoofoo="$foofoo $foo";

[prod]
foo="foo";
foofoo="bar";
foofoofoo="$foofoo $foo";

If we run the following code against this example:

source config-parser.sh;  # Either include the content of the file in your script, or source it for command line testing.
config_parser "example.ini";
config.section.dev;
echo "$foofoofoo";
config.section.prod;
echo "$foofoofoo";

We'll get this output:

foo bar
bar foo

config-parser's People

Contributors

peter-d avatar richardbronosky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

config-parser's Issues

apple supplied sed breaks parameter parsing in very particular circumstances

Just tracked down a very annoying bug. It is not a bug with config-parser but just thought I would throw it out there. If a parameter ends in 't' then the sed supplied by apple will remove the t. So 'test' becomes 'tes'. I installed posix sed and that fixed my problem. Just thought you might want to know. Thanks for this, I've been loving it.

A tiny correction in README.md

Please correct
config_parse "/path/to/example/file.ini";
as:
config_parser "/path/to/example/file.ini";

PS: Awesome code.

License?

What is the license for this script? Can I freely use, modify and distribute it?
(see http://choosealicense.com/ for more info on which license to pick)

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.