设置mac默认使用GNU工具,比如使用GNU cat而不是BSD cat |
您所在的位置:网站首页 › 如何举报gcat › 设置mac默认使用GNU工具,比如使用GNU cat而不是BSD cat |
mac和linux都是unix-like OS, 命令是有很多相似之处, 但也有很多不同之处. 比如cat命令, mac不支持-A选项. 使用起来不够方便. 这是因为mac的命令工具来自于BSD, 而linux默认是GNU. 让我决心换到GNU工具的是sed, 同样的sed命令, mac就运行不成功, 这是因为GNU实现了很多扩展. 类似情况的还有grep, 或许还有awk, 但awk我用得不多, 没感觉到区别. 好了, 废话不多说, 直接说怎么从mac的工具转到linux工具. 第一种方法(维护起来麻烦, 不建议) brew install coreutils findutils gnu-tar gnu-sed gawk gnutls gnu-indent gnu-getopt grep. 其实在做完这步以后, 不喜欢折腾的人可以不做下一步, 因为gcat就可以用GNU cat了. 类似有ggrep. 但是我同时装了linux虚拟机, 有时候需要shell脚本既在mac上执行, 又在linux上执行, 希望名称上可以更统一. 于是做下一步: 在~/.bash_profile中添加 gnu_path="/usr/local/opt/coreutils/libexec/gnubin:/usr/local/opt/findutils/libexec/gnubin:/usr/local/opt/gnu-tar/libexec/gnubin:/usr/local/opt/gnu-sed/libexec/gnubin:/usr/local/opt/gawk/libexec/gnubin:/usr/local/opt/gnu-indent/libexec/gnubin:/usr/local/opt/grep/libexec/gnubin" PATH=$gnu_path:$PATH MANPATH="/usr/local/opt/coreutils/libexec/gnuman:/usr/local/opt/findutils/libexec/gnuman:/usr/local/opt/gnu-tar/libexec/gnuman:/usr/local/opt/gnu-sed/libexec/gnuman:/usr/local/opt/gawk/libexec/gnuman:/usr/local/opt/gnu-indent/libexec/gnuman:/usr/local/opt/grep/libexec/gnuman":$MANPATH export PATH export MANPATH打开的新的session, readlink -e which cat, 以及man cat, 应该就是GNU了 第二种方法(初始设置麻烦一些, 但是后续添加非常方便)对于bin和man page分别用不同的方法 bin #!/usr/bin/env bash print_usage() { cat |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |