5

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.

7

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 macOS sed.

Note that the shell may have cached the location of sed already, if you have used the command on the command line. You may have to use hash -r to clear that cache, or open a new terminal.

  • 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.