简体   繁体   中英

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, eg 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")

同样的东西适用于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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM