views:

24

answers:

2

Suppose I have have a program P which has a filename as argument. For example

P file

reads the file "file" and does something with it.

Now sometimes the content of "file" is very small, e.g. just one line. So instead of creating a file f with that line and calling

P f

I want to give the content of line directly as an argument to P. I don't want to write a wrapper for P.

Is it possible to do this in zsh? How would be the syntax?

+3  A: 
P <(echo "something something")

Same thing works for bash.

Ignacio Vazquez-Abrams
Thanks! Thats what I wanted.
+1  A: 

There's no need to use process substitution if you already have a literal string or a variable. You can use a here string (which is a one-line here document).

With a literal string:

P <<< "f"

or, with a variable:

P <<< "$f"

The quotes can be omitted if you don't need to preserve whitespace.

This also works in Bash and ksh.

Dennis Williamson