简体   繁体   English

如何将变量作为临时文件传递给bash中的命令

[英]How to pass a variable as a temporary file to a command in bash

There exists a command foo which expects two arguments which are filenames and which prints some stuff on stdout. 有一个命令foo ,它期望有两个参数,即文件名,并在stdout上打印一些内容。

I have a Bash script with two variables a and b holding two strings. 我有一个带有两个a两个字符串的变量ab的Bash脚本。

I wish to pass to foo two filenames where the contents of those files are a and b . 我希望将两个文件名分别为ab传递给foo I then want to store the stdout as a new variable c . 然后,我想将标准输出存储为新变量c

Following ad hoc Googling, the script would perhaps look something like: 临时执行Google搜索后,该脚本可能类似于:

a=...;
b=...;
c=`foo <($a) <($b)`;

What should it look like? 应该是什么样子?

a=...
b=...
c=$(foo <(echo "$a") <(echo "$b"))

echo "$c"

Try using echo -e 尝试使用echo -e

a=...
b=...
c=$(foo <(echo -e "$a") <(echo -e "$b"))

echo -e "$c"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM