zsh 给出文件参数而不创建文件 - 语法?
假设我有一个程序 P,它以文件名作为参数。例如,
P file
读取文件“file”并对其执行某些操作。
现在有时“文件”的内容非常小,例如只有一行。因此,我不想用该行创建文件 f 并调用,而是
P f
想将行的内容直接作为参数提供给 P。我不想为 P 编写包装器。
是否可以在 zsh 中执行此操作?语法如何?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
同样的事情也适用于 bash。
Same thing works for bash.
如果您已经有文字字符串或变量,则无需使用进程替换。您可以使用此处字符串(这是单行此处文档)。
对于文字字符串:
或对于变量:
如果不需要保留空格,则可以省略引号。
这也适用于 Bash 和 ksh。
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:
or, with a variable:
The quotes can be omitted if you don't need to preserve whitespace.
This also works in Bash and ksh.