shorthand 用于在 bash 中创建空文件在 zsh 中无法正常工作
shorthand for creating empty file in bash not working properly in zsh
在 bash 中,可以创建一个空文件:
> empty_file.txt
在 zsh 中,相同的命令卡住,需要停止。尽管如此,文件还是被创建了。
我想知道是什么导致了这种行为and/or如何让它类似于bash?
编辑:打字错误。
如果您没有为重定向指定命令,那么 Bash 的行为(根据 POSIX)就像命令是 true
一样。默认情况下,除非在兼容模式下,否则 zsh
的行为就好像命令是 cat
.
您可以简单地显式指定命令 true
(或其 harder-to-read 别名 :
)以使两个 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.
在 bash 中,可以创建一个空文件:
> empty_file.txt
在 zsh 中,相同的命令卡住,需要停止。尽管如此,文件还是被创建了。
我想知道是什么导致了这种行为and/or如何让它类似于bash?
编辑:打字错误。
如果您没有为重定向指定命令,那么 Bash 的行为(根据 POSIX)就像命令是 true
一样。默认情况下,除非在兼容模式下,否则 zsh
的行为就好像命令是 cat
.
您可以简单地显式指定命令 true
(或其 harder-to-read 别名 :
)以使两个 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.