There is a command pdflatex, which I want to use in my bash script. It takes as input a filename on which content it will work.
Now I have an algorithms that looks as follows:
for stuff in list of stuff; do
echo "${stuff}" > /tmp/tmpStuff
pdflatex /tmp/tmpStuff
done
Now this works as expected. But I was thinking I could speed that up by doing less disk I/O(as > redirection writes to a file). I wish I could write something like echo "$stuff" | pdflatex /tmp/tmpStuff
but pdflatex uses a file and not stdin as its input. Is there any way of keeping "$stuff"
in memory and passing it to pdflatex as a sort of file?
TLDR: I would be happy if I could create a temporary file which could be named and be in memory.
You can use process substitution for this:
pdflatex <(echo "$stuff")
From the Bash Reference Manual:
3.5.6 Process Substitution
Process substitution is supported on systems that support named pipes (FIFOs) or the /dev/fd method of naming open files. It takes the form of
<(list)
or
>(list)
The process list is run with its input or output connected to a FIFO or some file in /dev/fd. The name of this file is passed as an argument to the current command as the result of the expansion. If the
>(list)
form is used, writing to the file will provide input for list. If the<(list)
form is used, the file passed as an argument should be read to obtain the output of list. Note that no space may appear between the < or > and the left parenthesis, otherwise the construct would be interpreted as a redirection.
And I also wonder if a here-string would make it as well:
pdflatex <<< "$stuff"
Many shells, and Linux as a whole, accept:
echo "${stuff}" | pdflatex /dev/stdin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With