【发布时间】:2016-09-20 05:23:15
【问题描述】:
我已经看到了太多这样的重复,但没有一个答案代码或提示对我有帮助,所以我很困惑。
input=/foo/bar/*;
#Contains something along the lines of
#/foo/bar/file1 /foo/bar/file2 /foo/bar/file3
#And I simply need
#/foo/bar/file3 /foo/bar/file2 /foo/bar/file1
output=($(for l in ${input[@]}; do echo $l; done | sort));
#Doesn't work, returns only the last entry from input
output=$(sort -nr ${input});
#Works, returns everything correctly reversed, but outputs the file contents and not the pathnames;
output=($(sort -nr ${input}));
#Outputs only the last entry and also its contents and not the pathname;
我尝试了更多选项,但我不会用它们填满整个页面,你明白要点了。
重复:(对我没有帮助)
【问题讨论】:
-
$input不是数组,而是字符串。另外,${a[@]}是如何填充的? -
@choroba Ops,我只是从另一个 SO 问题复制并粘贴,因为我没有代码了。
-
input正好包含字符串/foo/bar/*;赋值语句中不会发生路径名扩展。
标签: arrays linux bash shell sorting