12

I am using oh my zsh. I am not able to use some commands which I could do on ubuntu for e.g.. \s in regular expressions. I installed home-brew and then brew install gnu-sed --default-names but still I am unable to used sed command. My $PATH variable is a bit messed up and I am not sure how to correct it.

/Users/ishansrivastava/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/local/sbin:/opt/X11/bin:/Library/TeX/texbin

What should I do so that I can use all gnu commands without hassle on my Mac?Also please give me the list of commands on which I have to use gnu command instead of default for e.g.. gsed instead of sed etc.

1

1 Answer 1

12

As mentioned in another question, if installing GNU sed using Homebrew with --with-default-names, then it is installed as /usr/local/bin/sed.

Without --with-default-names, it will be installed as /usr/local/bin/gsed.

If installed as sed, then it depends on your $PATH what sed binary gets picked up when you execute sed. If your $PATH is as you have described, then GNU sed should have precedence over the native macOS sed.

Note that the shell may have cached the location of the sed command already if you have used the command on the command line previously in the same shell session. You may then use rehash in zsh to clear that cache, or open a new terminal.

When a system provides a native sed implementation that is not GNU sed, then it is often better to install GNU sed as gsed to not break existing scripts relying on behaviour specific to the native sed. This is why the default behaviour with Homebrew on macOS is to install GNU sed as gsed. This is also the default way to name GNU sed (and GNU tools in general) on other BSD systems.

4
  • i solved it. Apparently it installed in usr/local/Cellar/gnu-sed/4.4/bin. I added to the path. Still i would have liked to use gsed instead of changing what my actual sed did. Commented Sep 4, 2017 at 8:51
  • @IshanSrivastava I'm no Homebrew user, but wouldn't installing without --with-default-names allow you to use GNU Sed as gsed? Commented Sep 4, 2017 at 8:53
  • i installed it with default names. i finally get you. sorry for the trouble. but why did it get installed in such an awkward path as mine? Commented Sep 4, 2017 at 9:07
  • 1
    @IshanSrivastava Some info here: rkulla.blogspot.se/2014/03/the-path-to-homebrew.html Commented Sep 4, 2017 at 9:16

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.