开发者

zsh give file argument without creating a file - syntax?

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?


P <(echo "something something")

Same thing works for bash.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜