linux - 如何使用 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 次。它运行了 10 次,但只生成一个 result.txt。但是,我想要多个结果文件,例如,result1.txt
等。result2.txt
result3.txt
解决方案
由于迭代号 ( $i
) 作为参数传递给example.sh
from multiple.sh
,因此可以使用相同的方法在每次迭代时创建一个文件。为此,将最后一行更改example.sh
为:
Rscript /home1/R_scripts/abc.R > "result${1}.txt"
推荐阅读
- google-maps - 似乎无法向我的地图添加额外的 GLTF 标记(WebGL)
- python - MPI (mpi4py) - 如果第一个 test() 返回 false,则 irecv() 和 test() 不会在循环中工作
- excel - 如何避免 CSV 文件在使用 text-to-column 功能时将某些行更改为日期格式?
- javascript - JavaScript 排名排行榜
- ios - iOS推送通知声音停止使用天蓝色通知中心工作[根本没有声音]
- solr - 如何将 solr 中的日期格式从 yyyy-mm-ddThh:mm:ssZ 更改为“dd/MM/yyyy”?
- tailwind-css - 自动拉伸顺风体以适应其他div
- php - Elasticsearch 索引已更新,但文档不在其中(带有 php 的 ES)
- javascript - 为什么我的 guildMemberRemove 代码不起作用
- excel - 使用工作公式在 Excel 中使用 VBA 获取错误 400