declare -A d functionread_ini() { ini_file=$1 if [ -f "${ini_file}" ]; then whileread line; do # if [ -z $(echo "$line" | sed "s/^[^#]*\[\w+\].*$//") ]; then ifecho"$line" |grep -xq '^\s*\[[a-zA-Z0-9_\-]\+\].*$'; then # sec=$(echo "$line" | sed "s/^[^#]*\[\(.\+\)\].*$/\1/") sec=$(echo"$line" | sed "s/^\s*\[\([a-zA-Z0-9_\-]\+\)\].*$/\1/") flag=1 fi
if [ 1 -eq $flag ] && echo"$line" |grep -xq '^\s*\w\+\s*=\s*.*$'; then # item=$(echo "$line" |sed "s/^\s*\([a-zA-Z0-9_\-]\+\)\s*=.*$/\1/") item=$(echo"$line" |sed "s/^\s*\(\S\+\)\s*=.*$/\1/") value=$(echo"$line" |sed "s/^.*=\s*\(.\+\)\s*$/\1/") key="$sec/$item" d[$key]=$value fi done <"${ini_file}" fi }
if [ -f "${ini_file}" ]; then whileread line; do # if [ -z $(echo "$line" | sed "s/^[^#]*\[${section}\].*$//") ]; then ifecho"$line" | grep -xq "^\s*\[${section}\].*$"; then flag=1 fi
# if [ 1 -eq $flag ] && [ -z $(echo "$line" | sed "s/^[^#]*${item}.*$//") ]; then if [ 1 -eq $flag ] && echo"$line" | grep -xq "^\s*${item}\s*=\s*.*$"; then echo"$line" | sed "s/=.*$/=${value}/" flag=0 is_found=1 else echo"$line" fi done <"${ini_file}"# 从文件读取行,循环内的变量退出循环后仍有效;似乎~如果从管道读取则不然。 fi echo$flag,$is_found# 附上while循环中的变量值 }