Skip to content

Instantly share code, notes, and snippets.

View steveherrin's full-sized avatar

Steve Herrin steveherrin

  • Mountain View, CA
View GitHub Profile
@abiyani
abiyani / dedup_PATH.bash
Last active August 29, 2015 13:58
Removes duplicate paths from the input (which is assumed to be a "PATH-like" string)
# Removes redundant entries from the input (which is assumed to be a "PATH"-like string)
# Input: Exactly one argument ($1): a PATH-like string, which will be de-deuplicated
# Output: Prints the deduplicated string on stdout (can be captured using command substitution by caller)
#
# Notes:
# - Assumes colon (:) as the delimiter character.
# - The only assumption regarding actual pathnames within the input string is that they won't
# contain the delimiter character (':') - this shouldn't be a problem, because bash will
# anyway split on ":" unconditionally (http://stackoverflow.com/a/14661492/1857518). Any other
# valid pathname character (whitespaces, non-printable ascii values, etc) are ok (modulo some other