我正在尝试将Linux中的英文词典读入关联数组中,使用单词作为键和预定义字符串作为值。这样我就可以通过关键字查找单词是否存在。另外,我需要将所有的单词转换为小写字母。这很简单,但是bash语法让我感到困扰。当我运行下面的代码时,出现“bad array subscript”错误。有什么想法是为什么呢?
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'
相当于unset IFS
。 - jordanm${VAR,,}
的语法是什么?我以前从未见过这种语法,也找不到其他参考资料。 - Zoey Hewll