gpt4 book ai didi

bash - 如何测试 rm 的 GNU 或 BSD 版本?

转载 作者:行者123 更新时间:2023-11-29 09:01:27 24 4
gpt4 key购买 nike

rm 的 GNU 版本有一个很酷的 -I 标志。从联机帮助页:

-I     prompt once before removing more than three files, or when removing recursively.   Less
intrusive than -i, while still giving protection against most mistakes

Mac 不会:

$ rm -I scratch
rm: illegal option -- I
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file

有时人们在 Mac 上安装了 coreutils(GNU 版本),有时却没有。有没有办法在继续之前检测到这个命令行标志?我想在我的 bash_profile 中有这样的东西:

if [ has_gnu_rm_version ]; then
alias rm="rm -I"
fi

最佳答案

字符串/bin/rm | grep -q 'GNU coreutils'

如果 $?为0,就是coreutils

关于bash - 如何测试 rm 的 GNU 或 BSD 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6834355/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com