Skip to main content
added 104 characters in body
Source Link
konsolebox
  • 1.1k
  • 13
  • 14

You can do this:

#!/bin/bash 

declare -A sitesite=() themetheme=()

add_site() {
    local shortcut=$1
    site[$shortcut]=$2
    theme[$shortcut]=$3
} 

while IFS= read -r line; do
    case "$line" in
    shortcut=*)
        # IFS== read -r __ shortcut <<< "$line"
        shortcut=$_shortcut=${line#*=}
        ;;
    site=*)
        # IFS== read -r __ site <<< "$line"
        site=$_site=${line#*=}
        ;;
    theme=*)
        # IFS== read -r __ theme <<< "$line"
        theme=$_theme=${line#*=}
        add_site "$shortcut""$_shortcut" "$site""$_site" "$theme""$_theme"
        ;;
    esac
done < your_filefile.ini

Test output with added echo "$@" on function:

x1 example1.com alpha
x2 example2.com beta

You can do this:

#!/bin/bash
declare -A site theme
add_site() {
    local shortcut=$1
    site[$shortcut]=$2
    theme[$shortcut]=$3
}
while IFS= read -r line; do
    case "$line" in
    shortcut=*)
        # IFS== read -r __ shortcut <<< "$line"
        shortcut=${line#*=}
        ;;
    site=*)
        # IFS== read -r __ site <<< "$line"
        site=${line#*=}
        ;;
    theme=*)
        # IFS== read -r __ theme <<< "$line"
        theme=${line#*=}
        add_site "$shortcut" "$site" "$theme"
        ;;
    esac
done < your_file.ini

Test output with added echo "$@" on function:

x1 example1.com alpha
x2 example2.com beta

You can do this:

#!/bin/bash 

declare -A site=() theme=()

add_site() {
    local shortcut=$1
    site[$shortcut]=$2
    theme[$shortcut]=$3
} 

while IFS= read -r line; do
    case "$line" in
    shortcut=*)
        # IFS== read -r __ shortcut <<< "$line"
        _shortcut=${line#*=}
        ;;
    site=*)
        # IFS== read -r __ site <<< "$line"
        _site=${line#*=}
        ;;
    theme=*)
        # IFS== read -r __ theme <<< "$line"
        _theme=${line#*=}
        add_site "$_shortcut" "$_site" "$_theme"
        ;;
    esac
done < file.ini

Test output with added echo "$@" on function:

x1 example1.com alpha
x2 example2.com beta
added 74 characters in body
Source Link
konsolebox
  • 1.1k
  • 13
  • 14

You can do this:

#!/bin/bash
declare -A site theme
add_site() {
    local shortcut=$1
    site[$shortcut]=$2
    theme[$shortcut]=$3
}
while IFS= read -r line; do
    case "$line" in
    shortcut=*)
        # IFS== read -r __ shortcut <<< "$line"
        shortcut=${line#*=}
        ;;
    site=*)
        # IFS== read -r __ site <<< "$line"
        site=${line#*=}
        ;;
    theme=*)
        # IFS== read -r __ theme <<< "$line"
        theme=${line#*=}
        add_site "$shortcut" "$site" "$theme"
        ;;
    esac
done < your_file.ini

Test output with added echo "$@" on function:

x1 example1.com alpha
x2 example2.com beta

You can do this:

#!/bin/bash
declare -A site theme
add_site() {
    local shortcut=$1
    site[$shortcut]=$2
    theme[$shortcut]=$3
}
while IFS= read -r line; do
    case "$line" in
    shortcut=*)
        IFS== read -r __ shortcut <<< "$line"
        ;;
    site=*)
        IFS== read -r __ site <<< "$line"
        ;;
    theme=*)
        IFS== read -r __ theme <<< "$line"
        add_site "$shortcut" "$site" "$theme"
        ;;
    esac
done < your_file.ini

Test output with added echo "$@" on function:

x1 example1.com alpha
x2 example2.com beta

You can do this:

#!/bin/bash
declare -A site theme
add_site() {
    local shortcut=$1
    site[$shortcut]=$2
    theme[$shortcut]=$3
}
while IFS= read -r line; do
    case "$line" in
    shortcut=*)
        # IFS== read -r __ shortcut <<< "$line"
        shortcut=${line#*=}
        ;;
    site=*)
        # IFS== read -r __ site <<< "$line"
        site=${line#*=}
        ;;
    theme=*)
        # IFS== read -r __ theme <<< "$line"
        theme=${line#*=}
        add_site "$shortcut" "$site" "$theme"
        ;;
    esac
done < your_file.ini

Test output with added echo "$@" on function:

x1 example1.com alpha
x2 example2.com beta
Source Link
konsolebox
  • 1.1k
  • 13
  • 14

You can do this:

#!/bin/bash
declare -A site theme
add_site() {
    local shortcut=$1
    site[$shortcut]=$2
    theme[$shortcut]=$3
}
while IFS= read -r line; do
    case "$line" in
    shortcut=*)
        IFS== read -r __ shortcut <<< "$line"
        ;;
    site=*)
        IFS== read -r __ site <<< "$line"
        ;;
    theme=*)
        IFS== read -r __ theme <<< "$line"
        add_site "$shortcut" "$site" "$theme"
        ;;
    esac
done < your_file.ini

Test output with added echo "$@" on function:

x1 example1.com alpha
x2 example2.com beta