相关疑难解决方法(0)

如何遍历 bash 列表并获得 2 个元素的所有可能组合?

我有一个问题。我有一个包含许多文件的文件夹,我需要对我的文件中 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
Run Code Online (Sandbox Code Playgroud)

我是 bash 新手,在其他语言中,这看起来像:

for i in [0,N]
  for j in [i,N]
    #the combination would be i,j
Run Code Online (Sandbox Code Playgroud)

我的文件列表如下所示:

ex_10.1 ex_10.2 ex_10.3 ex_10.4 ex_10.5

我想对其中 2 个文件的所有组合执行一个 python …

bash shell

2
推荐指数
1
解决办法
1476
查看次数

标签 统计

bash ×1

shell ×1