libcrishini is a library that can be used by loading it with a shell script. This library uses various values by passing them to functions in several ways.
First, load this library with the source command in some way.
If you're root, you can easily install it on your system, or you can get the library with curl.
If you're arch linux user, you can install it with pacman
git clone https://github.com/Hayao0819/crshini
cd crshini
makepkg -siIf you have root permission , you can this library with make
git clone https://github.com/Hayao0819/crshini
cd crshini
sudo make installAfter install it, write this code to load
source "/usr/lib/libcrshini"If you want to use this library in portable script, you can load it from Github with curl. You don't need to install any packages, just include the following code in your shell script.
curl -sL "https://raw.githubusercontent.com/Hayao0819/crshini/dev/src/libcrshini" > "/tmp/libcrshini"
source "/tmp/libcrshini"You can check whether the library was loaded correctly with the following command.
echo "${_crshini_version}"If the library's functions are available, the library version will be displayed.
As of June 4, 2021, there are four main functions available.
The _crshini_get function is used to get information from an ini file.It is mainly used in the following syntax.
The code above specifies the file path.
_crshini_get file [section] [param]
cat file | _crshini_stdin=true _crshini_get [section] [param]Specifying sections and parameters is optional.
If no section is specified, a list of sections will be output.
If no parameter is specified, a list of parameters will be output.
In the example below, ini is read from standard input by setting _crshini_stdin to true.
Set the environment variable _crshini_get_linemode to get line number where the value is set instead of the value.
The _crshini_set function is used to set section , param and value. It is mainly used in the following syntax.
You can create new parameters or rewrite existing ones.
_crshini_set file section param value
cat file | _crshini_stdin=true _crshini_set section param valueNone of the arguments can be omitted.
This function is used to merge two INI files.It combines the file specified by the argument with the standard input file. The value of _crshini_stdin is ignored and always reads standard input.
cat input_file | _crshini_merge file [section]You can also limit the sections to be merged.
The _crshini_del function is used to delete section or param.
_crshini_del file section [param1] [param2] ...
cat file | _crshini_stdin=true _crshini_del section [param1] [param2] ...If no parameter is specified, all sections will be deleted. You can also specify multiple parameters.
You can change the behavior of the function with environment variables.
Set _crshini_stdin to true
Set _crshini_debug to true
Set _crshini_output to the path. Set - to output to standard output.
Set temporary file to the path. Default is /tmp/libcrshini.
Temporary files are used by some functions for a variety of purposes.
Set _crshini_get_linemode to true
This variable only works in some modes of _crshini_get. Otherwise it will be ignored.
The crshini command is also developed in this project as an implementation example of libcrshini.