2
A
回答
7
您可以将整个数组转换在o NE拍摄:
WHITELIST=("${WHITELIST[@],,}")
printf "%s\n" "${WHITELIST[@]}"
this
example
somthing
2
您可以使用${parameter,,}
:
WHITELIST=(
"THIS"
"examPle"
"somTHing"
)
i=0
for elt in "${WHITELIST[@]}"
do
NEWLIST[$i]=${elt,,}
i=$((${i} + 1))
done
for elt in "${NEWLIST[@]}"
do
echo $elt
done
从手册页:
${parameter,,pattern} Case modification. This expansion modifies the case of alpha‐ betic characters in parameter. The pattern is expanded to pro‐ duce a pattern just as in pathname expansion. The^operator converts lowercase letters matching pattern to uppercase; the , operator converts matching uppercase letters to lowercase. The ^^ and ,, expansions convert each matched character in the expanded value; the^and , expansions match and convert only the first character in the expanded value. If pattern is omit‐ ted, it is treated like a ?, which matches every character. If parameter is @ or *, the case modification operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with @ or *, the case modification operation is applied to each member of the array in turn, and the expansion is the resultant list.
0
一个这样做的方式:
$ WHITELIST=("THIS" "examPle" "somTHing")
$ x=0;while [ ${x} -lt ${#WHITELIST[*]} ]
do WHITELIST[$x]=$(tr [A-Z] [a-z] <<< ${WHITELIST[$x]})
let x++
done
$ echo "${WHITELIST[@]}"
this example somthing
相关问题
- 1. 使用XSL将所有元素名称转换为小写?
- 2. 将字符串数组元素转换为小写
- 3. 如何将数组中的所有元素转换为JavaScript中的整数?
- 4. 如何将数组元素转换为PHP中的simplae元素?
- 5. 我如何将这个元组元组转换为元素数?
- 6. 将所有元素转换为属性
- 7. 如何将所有浮点元素转换为矢量的整数元素
- 8. 如何将td中的所有兄弟元素转换为数组
- 9. 如何将多个textarea元素的所有文本转换为数组?
- 10. 液体 - 将数组转换为小写
- 11. 如何将数组转换为元组?
- 12. 将JSON数组转换为Bash数组
- 13. 将XML元素转换为数组
- 14. 如何在Vim中将所有文本转换为小写
- 15. 如何将小数转换为三元?
- 16. 如何将数组元素转换为Python中的整数
- 17. 我将如何将JSONObject的元素转换为单个元素数组?
- 18. 将特定的单元格数组元素转换为数组
- 19. 如何将live dom元素的数组转换为活的NodeList?
- 20. 将关联数组元素转换为小写,然后再显示它们
- 21. 将元组转换为元素列表
- 22. 如何将char数组转换为整数元素?
- 23. 如何使用atoi()将char数组的元素转换为int?
- 24. 将jQuery元素的数组转换为jQuery包装元素集
- 25. 将float系列中的所有元素转换为整数
- 26. 将所有大写标签转换为小写?
- 27. 将文件中的所有元素转换为haskell中的数组
- 28. 如何将现有DOM元素文本转换为HTML元素?
- 29. 如何将字符串转换为Bash中的所有空格?
- 30. 如何将分词转换为小写
良好的解决方案,但只'bash的4.x'。 –
*耸肩*和? :)'tr'(你的答案)是一个很好的回退。 –
不要误解我的意思,我只是觉得让OP知道防止不必要的心痛不能执行一个非常好的解决方案会很好。 :) –