繁体   English   中英

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

[英]shorthand for creating empty file in bash not working properly in 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.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM