如何在 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

查看:76
本文介绍了如何在 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

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

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 选项是 删除2019 年,所以现在该选项不再可用.

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

安装时,Homebrew 会指示如何调整路径,如果您想使用没有 g 前缀的 sed.

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

所以在你的情况下你要做的是:

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天全站免登陆