如何在Mac OS 10.10+上使用GNU sed,不再支持'brew install --default-names' [英] How to use GNU sed on Mac OS 10.10+, 'brew install --default-names' no longer supported

查看:842
本文介绍了如何在Mac OS 10.10+上使用GNU sed,不再支持'brew install --default-names'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mac OS 10.10.3下,我通过键入以下命令安装了gnu-sed:

Under Mac OS 10.10.3, I installed gnu-sed by typing:

brew install gnu-sed --default-names

当我再次键入它时,得到消息:

When I type it again, I get the message:

已经安装了gnu-sed-4.2.2

gnu-sed-4.2.2 already installed

但是,即使在重新启动系统并重新启动Terminal之后,我仍然无法使用GNU版本的sed.例如:

However, even after rebooting the system and restarting Terminal, I still cannot use the GNU version of sed. For example:

echo a | sed ’s_A_X_i’

返回: 替换命令"i"中的错误标志

returns: bad flag in substitution command 'i'

我应该怎么做才能使GNU版本正常工作? 这是我的$ PATH变量中的路径.

What should I do to get the GNU version working? Here are the paths in my $PATH variable.

/Users/WN/-myUnix
/opt/local/bin
/opt/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
/Applications/calibre.app/Contents/MacOS
/opt/ImageMagick/bin
/usr/texbin 

很抱歉,我的问题似乎很明显,但是我正在独自学习shell脚本,还不太了解如何安装UNIX程序.在我的Mac上使用与GNU兼容的命令(在这种情况下是sed,但不久以后我还将需要其他命令)的任何帮助而不会造成损坏或不必要的混乱,将不胜感激.

I'm sorry if my question seems obvious, but I am learning shell scripting on my own and don't quite understand yet how UNIX programs are installed. Any help to use GNU compliant commands (in this case sed, but soon I'll need others as well) on my Mac without causing damage or unnecessary clutter would be greatly appreciated.

推荐答案

注意(2019):

--with-default-names选项为

The --with-default-names option is removed since January 2019, so now that option is not available anymore.

在安装时,如果有人想使用不带g前缀的sed,Homebrew会指导如何修改路径.

When installing, Homebrew instructs on how to adapt the path, if one wants to use sed without the g prefix.

您已经安装了不带--with-default-names选项的gnu-sed.

You already have the gnu-sed installed without the --with-default-names option.

  • 使用--with-default-names选项,它将 sed 安装到/usr/local/bin/
  • 没有该选项,它将安装 gsed
  • With --with-default-names option it installs sed to /usr/local/bin/
  • Without that option it installs gsed

所以在您的情况下,您要做的是:

So in your case what you gotta do is:

$ brew uninstall gnu-sed
$ brew install gnu-sed --with-default-names

根据需要更新路径...

Update path if needed...

$ echo $PATH | grep -q '/usr/local/bin'; [ $? -ne 0 ] && export PATH=/usr/local/bin:$PATH
$ echo a | sed 's_A_X_i'

或按照其他建议使用 gsed .

or use gsed as others suggested.

这篇关于如何在Mac OS 10.10+上使用GNU sed,不再支持'brew install --default-names'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆