如何在 Linux 命令行中将多个输入指定为单个输入?

How to specify more inputs as a single input in Linux command-line?

我在网上搜索,但没有找到任何可以回答我问题的内容。

我在 Ubuntu Linux 中使用 java 工具,用 bash 命令调用它;这个工具有两个不同的输入文件的两个路径:

java -Xmx8G -jar picard.jar FastqToSam \
FASTQ=6484_snippet_1.fastq \ #first read file of pair
FASTQ2=6484_snippet_2.fastq \ #second read file of pair
[...]

例如,我想做的是,不是指定单个 FASTQ 的路径,而是指定两个不同文件的路径。

因此,与其使用 cat file1 file2 > File 并使用 File 作为 FASTQ 的输入,我希望该操作能够即时执行并创建 File 即时,而不将其保存在文件系统上(这就是命令 cat file1 file2 > File 所发生的情况)。

我希望我已经清楚地解释了我的问题,以防万一问我,我会尽力解释得更好。

大多数接受文件名参数的写得很好的 shell 命令通常也接受文件名参数列表。像 cat filecat file1 file2

如果您尝试使用的程序不支持此功能,并且无法轻易修复,也许您的 OS 或 shell 使 /dev/stdin 可用作伪文件.

cat file1 file2 | java -mumble -crash -burn FASTQ=/dev/stdin

一些 shells 也有进程替换,这(通常)看起来像一个包含进程替换在标准输出上产生的任何文件的调用程序。

java -mumble -crash -burn FASTQ=<(cat file1 file2) FASTQ2=<(cat file3 file4)

如果这些都不起作用,一个简单的 shell 使用临时文件并在完成后将其删除的脚本是一个久经考验的真实解决方案。

#!/bin/sh
: ${4?Need four file name arguments, will process them pairwise}
t=$(mktemp -d -t fastqtwoness.XXXXXXX) || exit
trap 'rm -rf $t' EXIT HUP INT TERM  # remove in case of failure or when done
cat "" "" >$t/1.fastq
cat "" "" >$t/2.fastq
exec java -mumble -crash -burn FASTQ=$t/1.fastq FASTQ2=$t/2.fastq