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

发布于 2024-09-26 03:18:56 字数 247 浏览 1 评论 0原文

假设我有一个程序 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆梦 2024-10-03 03:18:57
P <(echo "something something")

同样的事情也适用于 bash。

P <(echo "something something")

Same thing works for bash.

红墙和绿瓦 2024-10-03 03:18:57

如果您已经有文字字符串或变量,则无需使用进程替换。您可以使用此处字符串(这是单行此处文档)。

对于文字字符串:

P <<< "f"

或对于变量:

P <<< "$f"

如果不需要保留空格,则可以省略引号。

这也适用于 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:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文