Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • 4
    That's the only solution that i can internalize and remember without having to search for this question on SO again Commented Jun 12, 2020 at 18:45
  • 2
    This adds a : at the end of PATH every time the command is used, because grep appends an EOL (\n) to its output. Solve this by piping the output of grep through perl -pe 'chomp if eof'. Commented Feb 19, 2021 at 14:44
  • 1
    add another grep -v '^$' to remove empty ones. Commented Apr 1, 2021 at 0:07
  • 3
    To get rid of the trailing colon, you can also pipe the output to xargs, like so: echo $PATH | tr ":" "\n" | grep -v '/usr/local/bin' | xargs | tr ' ' ':' Commented Sep 15, 2021 at 23:12
  • 1
    A simple way to correctly undo tr : '\n' is paste -sd: - Commented May 20 at 19:17