0

下面的代码片段效果很好,但是我想稍微优化一下,我在顶部指定字体列表。现在我必须在顶部指定以及每次再次给出相同的字体名称时调用函数。如何将这些字体分组在顶部,然后调用函数来读取每个元素?我不确定如何在 shell 脚本中做到这一点(OSX,但我认为它非常接近常见的 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
4

1 回答 1

1

有几个选项:

  1. 您可以使用all=( "${MENU_ENGRUSFRA[@]}" "${DASHBOARD_1[@]}")
  2. 您可以修改process_ipad为简单地获取字体名称列表,而不是数组的名称。这可能更可取:

    process_ipad () {
      fontarr=( "$@" )
      ...
    }
    
    # all=("${MENU_ENGRUSFRA[@]}" "${DASHBOARD_1[@]}")
    # process_ipad "${all[@]}"
    process_ipad "${MENU_ENGRUSFRA[@]}" "${DASHBOARD_1[@]}"
    
于 2013-10-09T19:56:51.013 回答