如何解决在bash中创建空文件的简写在zsh中无法正常工作
在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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。