Pablo
Pablo

Reputation: 29519

How to combine arrays?

The following code snippet works well, however I would like to optimize a little that I specify font list just on top. Now I have to specify on top as well as call function every time giving again same font names. How can I group those fonts on top then just call function in order to read each element? I'm not sure how to do that in shell scripting (OSX, but I think it's very close to common unix shell)

# font list
MENU_ENGRUSFRA=("menu-engrusfra" "menu-engrusfra")
DASHBOARD_1=("dashboard-1" "dashboard-1")
# ... more goes here

process_ipad() {
    fontarr=("${!1}")
    project=${fontarr[0]}${PROJECT_EXT}
    hdfnt=${fontarr[1]}${HD_SUFFIX_IPAD}
    sdfnt=${fontarr[1]}

    # create HD .fnt
    GDCL $project $OUTPUT_IPAD_DIR$hdfnt

    # need arm conv for HD?
    contains $hdfnt "arm" && $ARM_CONV $OUTPUT_IPAD_DIR$hdfnt$FNT_EXT

    # create SD .fnt
    GDCL $project $OUTPUT_IPAD_DIR$sdfnt -rfs 0.5

    # need arm conv for SD?
    contains $sdfnt "arm" && $ARM_CONV $OUTPUT_IPAD_DIR$sdfnt$FNT_EXT

    echo "Done $sdfnt"
}

process_ipad MENU_ENGRUSFRA[@]
process_ipad DASHBOARD_1[@]
# sadly I have to mention here them as well

Upvotes: 0

Views: 142

Answers (1)

chepner
chepner

Reputation: 531055

There are a couple of options:

  1. You can make a single array with all=( "${MENU_ENGRUSFRA[@]}" "${DASHBOARD_1[@]}")
  2. You can modify process_ipad to simply take a list of font names, rather than the name of an array. This is probably preferable:

    process_ipad () {
      fontarr=( "$@" )
      ...
    }
    
    # all=("${MENU_ENGRUSFRA[@]}" "${DASHBOARD_1[@]}")
    # process_ipad "${all[@]}"
    process_ipad "${MENU_ENGRUSFRA[@]}" "${DASHBOARD_1[@]}"
    

Upvotes: 2

Related Questions