Kev*_*rke 5 bash shell bsd gnu
GNU版本rm有一个很酷的-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
Run Code Online (Sandbox Code Playgroud)
Mac不会:
$ rm -I scratch
rm: illegal option -- I
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
Run Code Online (Sandbox Code Playgroud)
有时人们coreutils在Mac上安装了(GNU版本),有时却没有.有没有办法在继续之前检测此命令行标志?我想在我的bash_profile中有这样的东西:
if [ has_gnu_rm_version ]; then
alias rm="rm -I"
fi
Run Code Online (Sandbox Code Playgroud)
我建议不要开始这条路.将脚本定位为尽可能的可移植性,并且只依赖于您可以依赖的标记/选项/行为.Shell脚本很难 - 为什么要添加更多错误空间?
为了了解我的想法,请查看Ryan Tomayko的Shell Haters演讲.他还有一个组织良好的页面,其中包含指向shell功能和实用程序的POSIX描述的链接.例如,这是rm.
我想说测试rm -I临时文件的输出,如果通过则使用别名
touch /tmp/my_core_util_check
if rm -I /tmp/my_core_util_check > /dev/null 2>&1 ; then
alias rm="rm -I"
else
rm /tmp/my_core_util_check;
fi
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1808 次 |
| 最近记录: |