我试图将Linux中的英文字典读入关联数组,使用单词作为键和预定义的字符串作为值。这样我可以按键查找单词,看看它们是否存在。我还需要所有的话都是小写。这很简单,但bash语法正在我的方式。当我运行下面的代码时,出现'bad array subscript'错误。任何想法,为什么这可能是?在变量bash关联数组中使用变量作为键
function createArrayFromEnglishDictionary(){
IFS=$'\n'
while read -d $'\n' line; do
#Read string into variable and put into lowercase.
index=`echo ${line,,}`
englishDictionaryArray[$index]="exists"
done < /usr/share/dict/words
IFS=$' \t\n'
}
'IFS = $'\ t \ n'与'未设置的IFS'相同。 – jordanm 2012-03-19 02:36:01
语法'$ {VAR ,,}'是什么?我从来没有见过这个,并且在别处找不到任何引用 – 2017-10-04 08:00:32
${VAR,,}
在Bash中表示小写。 – philcolbourn 2017-12-06 00:28:47