1

I have a command command that takes an input file as argument. Is there a way to call command without actually creating a file?

I would like to achieve the following behavior

$ echo "content" > tempfile
$ command tempfile
$ rm tempfile

if possible:

  • as a one-liner,
  • without creating a file,
  • using either a bash (or sh) feature or a "well-known" command (as standard as xargs)

It feels like there must be an easy way to do it but I can't find it.

1

1 Answer 1

6

Just use a process substitution.

command <(echo "content")

Bash will create a FIFO or other type of temporary file in /dev for the standard output of whatever happens in the process. For example:

$ echo <(echo hi)
/dev/fd/63
Sign up to request clarification or add additional context in comments.

3 Comments

Here string would be another option: command <<< "content". Then, a pipe: echo "content" | command
@EugeniuRosca I think that misrepresents the original question. Presumably OP has a command that expects a file, not simply standard input. Although, many such commands will look in standard input if the file name is -.
You are right. If the OP's command expects a filename as argument and the command cannot be altered by OP to accept stdin, then my suggestions are wrong. Thanks for feedback.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.