Saturday, October 29, 2022

[SOLVED] using a Bash variable in place of a file as input for an executable

Issue

I have an executable that is used in a way such as the following:

executable -v -i inputFile.txt -o outputFile.eps

In order to be more efficient, I want to use a Bash variable in place of the input file. So, I want to do something like the following:

executable -v -i ["${inputData}"] -o outputFile.eps

Here, the square brackets represent some clever code.

Do you know of some trick that would allow me to pipe information into the described executable in this way?

Many thanks for your assistance


Solution

You can use the following construct:

<(command)

So, to have bash create a FIFO with the command as the output for you, instead of your attempted -i ["${inputData}"], you would do:

-i <(echo "$inputData")

Therefore, here is your final total command:

executable -v -i <(echo "$inputData") -o outputFile.eps


Answered By - mikyra
Answer Checked By - Timothy Miller (WPSolving Admin)