2

我有 32 个文件(以相同的模式命名,唯一的区别是下面写的 $sample 编号),我想将它们分成 4 个文件夹。我正在尝试使用以下脚本来完成这项工作,但该脚本无法正常工作,有人可以帮我使用以下 shell 脚本吗?- 谢谢

#!/bin/bash

max=8    #8 files in each sub folder
numberFolder=4
sample=0

while ($numberFolder > 1) #skip the current folder, as 8 files will remain
do
  for (i=1; i<9; i++)
  do
   $sample= $i * $numberFolder   # this distinguish one sample file from another
   echo "tophat_"$sample"_ACTTGA_L003_R1_001"  //just an echo test, if works, will replace it with "cp".

  done
$numberFolder--
end
4

1 回答 1

2

您需要(( ))正确使用数学上下文。

#!/bin/bash

max=8
numberFolder=4
sample=0

while (( numberFolder > 1 )); do # math operations need to be in a math context
  for ((i=1; i<9; i++)); do # two (( )), not ( ).
    (( sample = i * numberFolder ))
    echo "tophat_${sample}_ACTTGA_L003_R1_001" # don't unquote before the expansion
  done
  (( numberFolder-- )) # math operations need to be inside a math context
done
于 2013-08-21T19:14:02.113 回答