如何使用 Shell 创建不同名称的输出文件?

How to create output files with different names using Shell?

我有一个 R 脚本 (abc.R):

#!/usr/bin/env Rscript

print("HELLO")

以及包含 R 脚本的批处理脚本 (example.sh):

#!/bin/bash
module load Rstats
module load RstatsPackages


Rscript /home1/R_scripts/abc.R   > "result.txt"

还有另一个批处理脚本(multiple.sh),它调用上面的脚本:

#!/bin/sh

for((i=1;i<=10;i++))
do

     sbatch -p normal -t 4:00:00 -N 1 -n 4 example.sh $i

done

sh multiple.sh

此脚本调用上述脚本十次,这样我的 Rscript 就会 运行 10 次。它是 运行ning 10 次,但只生成一次 result.txt。但是,我想要多个结果文件,例如 result1.txtresult2.txtresult3.txt 等等。

由于迭代次数 ($i) 作为参数从 multiple.sh 传递给 example.sh,所以每次迭代都可以使用相同的方法创建一个文件。为此,将 example.sh 的最后一行更改为:

Rscript /home1/R_scripts/abc.R   > "result.txt"