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.


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.


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.

  • 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. – Ishan Srivastava Sep 4 '17 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? – Kusalananda Sep 4 '17 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? – Ishan Srivastava Sep 4 '17 at 9:07
  • 1
    @IshanSrivastava Some info here: rkulla.blogspot.se/2014/03/the-path-to-homebrew.html – Kusalananda Sep 4 '17 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.