如何在linux bash shell中对字符串数组进行排序? [英] How can I sort the string array in linux bash shell?
本文介绍了如何在linux bash shell中对字符串数组进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,数组为
link2_pathname
link1_pathname
link3_pathname
如何获取如下所示的数组.
How can I get the array like below.
link1_pathname
link2_pathname
link3_pathname
非常感谢!
推荐答案
将循环传递给 sort
.
a=(l2 l3 l1)
b=($(for l in ${a[@]}; do echo $l; done | sort))
在处理包含空格的字符串值时,您可能需要注意IFS.
you probably need to watch out for the IFS when handling string values containing spaces.
这篇关于如何在linux bash shell中对字符串数组进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文