sh 将INI文件解析为Bash字典

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 将INI文件解析为Bash字典相关的知识,希望对你有一定的参考价值。

[SCRIPTS]
conos-pgsql-executor = "116.54"
[WARS]
admin_war = "116.04"
user_war = "116.04"
app_war = "116.04"
[SQL]
SC_AAU_CONOS_user = "116.54"
SC_AAU_CONOS_admin = "116.54"
#!/bin/bash
# set -x

# Use DONE in order to read until the last line of the file
DONE=false
until $DONE
do
	IFS='= ' read -r key val || DONE=true
	# If entry is a section, create dictionary using its name
	if [[ $key == \[*] ]]; then
		key=${key//[/}
		key=${key//]/}
		section=$key
		declare -A eval $section
	# If entry has a value, feed the dictionary with key:value
	elif [[ $val ]]; then
		eval "$section[${key}]=${val}"
	fi

done < variables.ini

for file in ${!WARS[@]}; do
	echo "WAR file is $file with version: ${WARS[$file]}"
done

for file in ${!SQL[@]}; do
	echo "SQL file is $file with version: ${SQL[$file]}"
done

for file in ${!SCRIPTS[@]}; do
	echo "SCRIPS file is $file with version: ${SCRIPTS[$file]}"
done


以上是关于sh 将INI文件解析为Bash字典的主要内容,如果未能解决你的问题,请参考以下文章

sh 使用BASH直接解析.env(dotenv)文件

sh 将sh文件转换为bash,反之亦然

sh RECURSIVELY Bash将所有html转换为markdown文件(使用Pandoc)

sh Bash脚本使用Applescript将目录中的所有html文件转换为docx文件。它还将标题和普通字体转换为

使用Python将ini文件中的所有内容读入字典

sh Bash:论证解析