bash - 为什么 ZSH 卡在空重定向上?

标签 bash shell zsh

要在 unixy 环境中截断文件,您通常会使用:

$ > file

在 bash(也是破折号)中,文件被截断(如果不存在则创建),然后提示符返回。在 zsh 中,文件被截断/创建,但挂起。您必须 Ctrl-C 才能再次使用提示。

重定向非空输出没有问题:

zsh$ cat nonempty.file > file
zsh$

问题是:

这种行为是否符合预期? zsh 错误吗?

最佳答案

我不是真正的 zsh 用户,但看起来 zsh 中的 > file 与 bash 中的 cat > file 相同。要在 zsh 中创建新文件或截断它,请使用 : > file。这也适用于 bash。


更新:

在 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 emulating 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 instead of that of the former when the redirection is an input. The default for NULLCMD is cat and for READNULLCMD is more.

在我的系统上,默认是:

$ echo $ZSH_VERSION
4.3.10
$ echo $NULLCMD
cat
$ echo $READNULLCMD
/usr/bin/pager
$

关于bash - 为什么 ZSH 卡在空重定向上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15545311/

相关文章:

bash - 使用 Until 在进程终止时重新启动进程

c++ - 如何将 'ls'(或任何其他 shell 命令)的输出重定向到管道?

bash - 在每一行中搜索一个模式并将其附加到该行的末尾

linux - 计算 shell 脚本每一步的时间并显示总执行时间

ruby - 警告 : PATH set to RVM ruby but GEM_HOME and/or GEM_PATH not set, 请参阅 : https://github. com/wayneeseguin/rvm/issues/3212

vim - 在 ZSH 中搜索当前行(vi 模式)

Bash 引用同一行中的先前参数

bash - 从多个目录创建多个 tar.gz 存档

regex - 当格式不固定时,如何从 shell 变量的末尾提取时间戳?

linux - shell 脚本启动和停止函数中意外的代码执行顺序