zsh - 为什么 rm -f 要求我在 zsh 上进行确认?

标签 zsh

我正在从 Cygwin 运行 zsh。我的一个 shell 函数包含一个语句

rm -f somedir/*

(我想删除 somedir 中的所有非隐藏文件,但不是目录本身)。然而,我总是被问到:
zsh: sure you want to delete all the files in ... [yn]?

此消息的措辞(注意开头的“zsh:”)表明问题来自 zsh,而不是 rm。但是, rm 是一个外部命令:
$ type rm
rm is /usr/bin/rm

顺便说一句,如果我显式调用 rm 作为
$ command rm -f somedir/*

zsh 中是否有一些东西试图过于聪明?

最佳答案

看来RM_STAR_SILENT不是 有效。
你可以做 setopt rmstarsilent在命令行或 ~/.zshrc 中告诉 zsh 不确认 rm * .
shell 选项 RM_STAR_SILENT是:

Do not query the user before executing rm * or rm path/*.

-- zshoptions(1): RM_STAR_SILENT



如果您想制作 setopt仅在该 shell 函数中暂时起作用,您可以将它与 localoptions 结合使用像下面这样:
my-test () {
  setopt localoptions rmstarsilent
  ...
}

关于zsh - 为什么 rm -f 要求我在 zsh 上进行确认?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27988160/

相关文章:

bash - 将函数从 zsh 导出到 bash 以便在 gnu parallel 中使用

git - zsh git 自动完成 : __git_find_on_cmdline error

linux - ZSH 中的文件完成优先级

bash - $RANDOM 从函数返回时保持不变

unix - 为什么zsh通配符无法与find命令一起使用?

macos - 在 zsh PS1(提示)env var 中使用自定义颜色会导致空格问题

linux - 在终端中显示大数字

homebrew - Brew 版本未知命令小牛

shell - 带参数的 ZSH 别名

bash - 无法在 Zsh 中使用类似 Bash 的 C-x-e