在shell中使用相同的for循环打开多个目录

时间:2014-04-08 19:46:43

标签: bash shell sh

folder_name=(MI IG Chi-square)
for m in {0..2}
do
    folder=${folder_name[$m]}
    echo
    echo  $folder
    echo
    train_path="/home/user/Thesis/DVD/Features/Training/POSITIVE/$folder/Unigram/"
    test_path="/home/user/Thesis/DVD/Features/Testing/POSITIVE/$folder/"
    for f,k in $train_path $test_path 
    do
       if $f in *.arff and $k in *.arff ; then
      echo $f,$k
    done
done

这是打开两个目录的代码,例如train_path和$ test_path,我想同时从这些路径中提取所有arff文件。我可以解决这个问题吗?任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

使用Bash 4,或许类似

shopt -s nullglob
base=/home/user/Thesis/DVD/Features
printf '%s\n' "$base/"{Training,Testing}/POSITIVE/{MI,IG,Chi-square}/{Unigram,}/*.arff |
  xargs -P2 extract {}

如果extract是提取arff文件的命令。您也可以使用相同的参数来使用GNU parallel。