【发布时间】:2017-10-12 21:25:18
【问题描述】:
我有一个问题。我有一个包含许多文件的文件夹,我需要对我的文件中的 2 个文件的所有组合执行程序。
到目前为止,我的 linux bash 脚本如下所示:
for ex in $(ls ${ex_folder}/${testset_folder} | sort -V ); do
#ex is the name of my current file
#I would like to do something like a nested loop where
# ex2 goes from ex to the end of the list $(ls ${ex_folder}/${testset_folder} | sort -V )
done
我是 bash 新手,在其他语言中,这看起来像:
for i in [0,N]
for j in [i,N]
#the combination would be i,j
我的文件列表如下所示:
ex_10.1 ex_10.2 ex_10.3 ex_10.4 ex_10.5
我想在其中 2 个文件的所有组合上执行一个 python 程序(所以我执行我的程序 10 次)
提前感谢您的帮助!
【问题讨论】:
-
是的,
for循环可以嵌套。只要确保每个人都有一个结束do/done。如果这还不足以帮助您,那么您没有告诉您的文件有些问题。更新您的 Q 以包含一小组文件名并显示您希望它们如何组合。祝你好运。 -
(顺便说一句,你的问题不是很准确,但你应该avoid parsing
ls)。