加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 为什么ZSH挂起空重定向?

发布时间:2020-12-16 01:09:31 所属栏目:安全 来源:网络整理
导读:要在unixy环境中截断文件,通常会使用: $ file 在bash(也是破折号)中,文件被截断(或者如果它不存在则创建),然后提示返回.在zsh中,文件被截断/创建,但它会挂起.您必须使用Ctrl-C才能再次使用提示. 重定向非空输出可以正常工作: zsh$cat nonempty.file filezs
要在unixy环境中截断文件,通常会使用:
$> file

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

重定向非空输出可以正常工作:

zsh$cat nonempty.file > file
zsh$

问题是:

是否期望这种行为? zsh错了吗?

我不是真正的zsh用户,但似乎> zsh中的文件与cat>相同bash中的文件.要在zsh中创建新文件或将其截断,请使用:>文件.这也适用于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
$

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读