0

私は bash でスクリプトを書いていて、配列から読み込もうとしています。以下のコードで配列を反復処理すると:

for item in "${!functionDict[@]}"
do
    echo "{ $item : ${functionDict[$item]} }" >> array.txt
done

出力します(「array.txt」内):

{  month_start_date($year_selected, $month_selected) : return $date; }
{  logWarning($message) : return logEvent($message, $c_event_warning); }
{  daysPastLastQuarterX($curYear, $curMonth, $curDay, $selected_year, $selected_quarter,   $nDays) : return false;:return false;:return false;:return false;:return true;:return $delta > $nDays; }
{  setExcelLabelCell($sheet, $cell, $label, $width) :  }
{  asCurrencyString($value) : return formatCurrency($value); }
{  getNumericMonthName($m) : return $numericMonth; }
{  normalize_for_PDF(&$text) :  }

ただし、配列から個々の要素を照会するのに問題があります。

私は試しました

string='month_start_date($year_selected, $month_selected)'
echo "test_output: ${functionDict[$string]}"

しかし、私は得る

test_output: <blank>

キーの周りに空白がある場合に備えて、いくつかの RegEx ワイルドカードを挿入してみました。

echo 'size of array: '"${#functionDict[@]}"
echo "TEST: functDict[logWarning] = ${functionDict[.*'logWarning($message)'.*]}"

私は得る

size of array: 157   //I didn't copy/paste all the elements in the array in this post
TEST: functDict[logWarning] = <blank>

ああ、私は立ち往生しています。私が取り戻そうとしているコンテンツは、「return _」アイテム、または「return」アイテムを持たないキーの単なる「空白」です。

4

1 に答える 1