在OSX上安装了GNU grep,但不能使用 [英] Installed GNU grep on OSX, but can't use

查看:317
本文介绍了在OSX上安装了GNU grep,但不能使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试在OSX上安装GNU grep,并且似乎已经安装了,但是我不能使用它..我已经使用自制软件完成了此操作,Macports当前遇到了一些问题,因此我无法使用那.

I've tried installing GNU grep on OSX, and it seems to be installed, but I can't use it.. I've done so using homebrew, Macports is having some issues currently, so I can't use that.

要安装:brew tap homebrew/dupes; brew install grep

哪个返回:Warning: homebrew/dupes already tapped! Warning: homebrew/dupes/grep-2.21 already installed

符号链接似乎可用于/usr/local/bin/ggrep.当我添加别名alias grep="ggrep"并执行grep --version时,得到-bash: ggrep: command not found.的确如此,因为该文件夹中没有ggrep.我尝试使用--with-default-names和不使用--with-default-names进行安装.

Symlinking seems to work to /usr/local/bin/ggrep. When I add the alias alias grep="ggrep" and do grep --version, I get -bash: ggrep: command not found. Which is true, since there is no ggrep in the folder. I've tried installing with and without --with-default-names.

文件夹/usr/local/Cellar/grep/2.21/bin/包含以下内容:

-r-xr-xr-x 1 Wes admin 158 Oct 14 09:27 egrep
-r-xr-xr-x 1 Wes admin 158 Oct 14 09:27 fgrep

这对我来说很奇怪,因为文档暗示The command has been installed with the prefix "g".

Which is strange to me, since the documentation implies that The command has been installed with the prefix "g".

我看过以下帖子,但是没有一种解决方案适合我. 为Mac OS 10.7更新grep

I've seen the following post, but none of the solutions work for me. Updating grep for Mac OS 10.7

有人有什么解决方案吗?我真的很想使用GNU grep.

Does anyone have any solutions? I really want to use GNU grep.

brew unlink grep && brew link grep -v的输出:

Unlinking /usr/local/Cellar/grep/2.21...
6 symlinks removed
Linking /usr/local/Cellar/grep/2.21...
ln -s ../Cellar/grep/2.21/bin/egrep egrep
ln -s ../Cellar/grep/2.21/bin/fgrep fgrep
ln -s ../../Cellar/grep/2.21/share/info/grep.info grep.info info /usr/local/share/info/grep.info
ln -s ../../../Cellar/grep/2.21/share/man/man1/egrep.1 egrep.1
ln -s ../../../Cellar/grep/2.21/share/man/man1/fgrep.1 fgrep.1
ln -s ../../../Cellar/grep/2.21/share/man/man1/grep.1 grep.1
6 symlinks created`

新功能: brew uninstall grep; brew install grep

$ which -a grep
/usr/bin/grep

$ which -a ggrep
/usr/local/bin/ggrep

$ echo $PATH
/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin

这一次,似乎有所不同.终于安装了ggrep!我认为unlink/link可以理顺一些内容. 如何将ggrep设置为默认值?使用alias吗?

This time, it seems something is different. ggrep is finally installed! I think the unlink/link straightened some things out. How can I set ggrep as the default? With alias?

推荐答案

要使GNU grep成为默认设置,请使用--with-default-names进行安装:

To make GNU grep the default install it with --with-default-names:

$ brew install grep --with-default-names

如果已经安装它,请使用reinstall而不是install.

If you already have it installed use reinstall instead of install.

确保您的$PATH中的/usr/local/bin(GNU grep的位置)在之前 /usr/bin(BSD grep的位置);

Ensure that /usr/local/bin (the location of GNU grep) is before /usr/bin (the location of the BSD grep) in your $PATH; which seems to be the case here.

由于Bash缓存了当前会话的二进制路径,因此您可能必须在之后启动一个新的Shell会话.这意味着您第一次使用grep时,它将根据您的$PATH确定要使用的二进制文件并将其缓存.下次它将使用缓存的值,因此更改$PATH不会更改任何内容,除非您重新加载Shell.

You might have to start a new shell session afterward because Bash caches the binaries paths for the current session. This means that the first time you use grep it’ll determine which binary it’ll use depending on your $PATH and cache it. The next time it’ll use the cached value so changing your $PATH won’t change anything until you reload the shell.

这篇关于在OSX上安装了GNU grep,但不能使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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