gpt4 book ai didi

linux - 在 bash 中创建空文件的简写在 zsh 中无法正常工作

转载 作者:行者123 更新时间:2023-12-03 09:53:50 24 4
gpt4 key购买 nike

在 bash 中,可以创建一个空文件:

> empty_file.txt

在 zsh 中,相同的命令卡住了,需要停止。尽管如此,文件还是被创建了。

我想知道是什么导致了这种行为和/或如何使其类似于 bash?

编辑:打字错误。

最佳答案

如果您没有为重定向指定命令,那么 Bash 的行为(根据 POSIX)就像命令为 true 一样。默认情况下,除非在兼容模式下,否则 zsh 的行为就好像命令是 cat 一样。

您可以简单地显式指定命令 true(或其更难阅读的别名 :)以使两个 shell 的行为相同:

: > empty_file.txt

这里是 man zsh 解释行为和你可以用来调整它的选项:

   REDIRECTIONS WITH NO COMMAND

When a simple command consists of one or more redirection operators
and zero or more parameter assignments, but no command name, zsh
can behave in several ways.

If the parameter NULLCMD is not set or the option CSH_NULLCMD is
set, an error is caused. This is the csh behavior and CSH_NULLCMD
is set by default when emulating csh.

If the option SH_NULLCMD is set, the builtin `:' is inserted as a
command with the given redirections. This is the default when emu‐
lating sh or ksh.

Otherwise, if the parameter NULLCMD is set, its value will be used
as a command with the given redirections. If both NULLCMD and
READNULLCMD are set, then the value of the latter will be used in‐
stead of that of the former when the redirection is an input. The
default for NULLCMD is `cat' and for READNULLCMD is `more'. Thus

< file

shows the contents of file on standard output, with paging if that
is a terminal. NULLCMD and READNULLCMD may refer to shell func‐
tions.

关于linux - 在 bash 中创建空文件的简写在 zsh 中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64579083/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com