In bash or shell, how to enter a line of text into a file without creating a temporary file?
Problem 1:
I am using a homemade command that cannot be changed for reasons. The command needs a filename, which it will read like this: read-cmd "testtext.txt"
I know it is possible to use files as input stream for some commands using input redirection, for example. some-cmd < "text.txt"
but I am wondering if the opposite is true, can I use a line of text and make bash believe this file so that I can doread-cmd "contents of what should be in a text file"
The only thing I could do was
Example 1:
echo "contents of what should be in a text file" > tmptextfile
read-cmd "tmptextfile"
rm tmptextfile
I would rather not do this, but rather just sink this line as if it were a file. Is there any possible way to do this, or will it rely entirely on how it works read-cmd
?
Problem 2:
However, a very similar problem, instead of the file being the input to the command, it is the input parameter to the command. So,read-cmd2 -d "testtext.txt" ...
Example 2:
echo "contents of what should be in options text file" > tmpoptfile
read-cmd2 -d tmpoptfile ...
rm tmpoptfile
source to share
can i use a line of text and make bash believe this file,
Yes, you can use process substitution for this:
read-cmd <(echo "contents of what should be in a text file")
Process substitution is a form of redirection where the input or output of a process (some sequence of commands) is displayed as a temporary file.
source to share