gpt4 book ai didi

shell 脚本 : for-loop within while loop

转载 作者:行者123 更新时间:2023-12-05 04:18:05 27 4
gpt4 key购买 nike

我有 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

最佳答案

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

#!/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

关于 shell 脚本 : for-loop within while loop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18365662/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com