zsh:创建命名文件代替参数?
zsh: create named file in place of argument?
realpath <<<'foo'
失败“真实路径:缺少操作数”。我不知道那是什么意思。
realpath <(<<<'foo')
returns /proc/3443695/fd/pipe:[26244650]
我猜这意味着它正在创建一个包含字符串“foo”的临时管道。
或者 printf
更清楚:
❯ printf "%q" <<<'foo' # no output
❯ printf "%q" <(<<<'foo')
/proc/self/fd/11%
我尝试调用的实际程序不喜欢其中任何一个。我想我需要一个实际的文件。
我可以通过使用 mktemp
创建一个文件然后写入它,然后将其作为 arg 发送出去,在多个命令中执行此操作,但是 zsh 是否有任何方便的语法来就地执行此操作? 1 线?
看起来 =(list)
进程替换应该可以满足您的要求。
来自 zshexpn
手册页:
If =(...) is used instead of <(...), then the file passed as an
argument will be the name of a temporary file containing the output
of the list process. This may be used instead of the < form for a
program that expects to lseek on the input file.
...
The temporary file created by the process substitution will be deleted when the function exits.
在我的系统上,realpath =(<<<'foo')
returns 类似 /private/tmp/zsh3YAdDx
的东西,即一个临时文件的名称,它确实在执行命令后似乎被删除了。
作为奖励,文档指出在某些情况下 =(<<<...)
表单经过优化以在当前 shell.
中完全执行
realpath <<<'foo'
失败“真实路径:缺少操作数”。我不知道那是什么意思。
realpath <(<<<'foo')
returns /proc/3443695/fd/pipe:[26244650]
我猜这意味着它正在创建一个包含字符串“foo”的临时管道。
或者 printf
更清楚:
❯ printf "%q" <<<'foo' # no output
❯ printf "%q" <(<<<'foo')
/proc/self/fd/11%
我尝试调用的实际程序不喜欢其中任何一个。我想我需要一个实际的文件。
我可以通过使用 mktemp
创建一个文件然后写入它,然后将其作为 arg 发送出去,在多个命令中执行此操作,但是 zsh 是否有任何方便的语法来就地执行此操作? 1 线?
看起来 =(list)
进程替换应该可以满足您的要求。
来自 zshexpn
手册页:
If =(...) is used instead of <(...), then the file passed as an argument will be the name of a temporary file containing the output of the list process. This may be used instead of the < form for a program that expects to lseek on the input file.
...
The temporary file created by the process substitution will be deleted when the function exits.
在我的系统上,realpath =(<<<'foo')
returns 类似 /private/tmp/zsh3YAdDx
的东西,即一个临时文件的名称,它确实在执行命令后似乎被删除了。
作为奖励,文档指出在某些情况下 =(<<<...)
表单经过优化以在当前 shell.