BASH: loop files numbered by #{number} in sorted order
本问题已经有最佳答案,请猛点这里访问。
这类似于BASH:如何按排序顺序循环播放所有文件
但我感到与众不同
我有一系列文件加上井号和数字,默认情况下,bash中的文件按以下顺序排序:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #1 Clear.png #10 Brilliant Blue.png #11 Caribbean Blue.png #12 Aquamarine.png #13 Teal.png #14 Turquoise.png #15 Green.png #16 Light Green.png #17 Purple.png #18 Lt Purple.png #19 Yellow.png #2 Standard Pink.png #20 Brown.png #3 Light Pink.png #4 Fuschia.png #5 Wine.png #6 Red.png #7 Orange.png #8 Blue.png #9 Light Blue.png |
我想按以下顺序在for循环中按井号前面的数字值对它们进行排序:
1 2 3 | for i in `ls * | sort [method to sort]`; do *stuff* done |
问题在于,我发现的所有排序解决方案似乎都不能很好地用于对带有磅符号和/或空格的案件进行排序。
订单文件应排序:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #1 Clear.png #2 Standard Pink.png #3 Light Pink.png #4 Fuschia.png #5 Wine.png #6 Red.png #7 Orange.png #8 Blue.png #9 Light Blue.png #10 Brilliant Blue.png #11 Caribbean Blue.png #12 Aquamarine.png #13 Teal.png #14 Turquoise.png #15 Green.png #16 Light Green.png #17 Purple.png #18 Lt Purple.png #19 Yellow.png #20 Brown.png |
编辑:刚才我意识到我的答案与您所链接问题的答案几乎相同。 所以绝对是重复的