简体   繁体   English

zsh给出文件参数而不创建文件-语法?

[英]zsh give file argument without creating a file - syntax?

Suppose I have have a program P which has a filename as argument. 假设我有一个程序P,该程序以文件名作为参数。 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 因此,与其在该行创建文件f并调用

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. 我想直接将line的内容作为P的参数。我不想为P写一个包装器。

Is it possible to do this in zsh? 有可能在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). 您可以使用here字符串(这是单行here文档)。

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. 这也适用于Bash和ksh。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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