Skip to main content
properly handle paths with spaces
Source Link
Varp
  • 11
  • 2

The right way of removing duplicates suggested by @ghm1014 and @rush (in the comment) using sort:

PATH=`echo -e ${PATH//:/'\n'} | awk '{printf("%d|%s\n", NR, $0)}' | sort -t '|' -k 2 -u | sort -t '|' -k 1 -g | cut -f2 -d'|'`; export PATH=${PATH//[[:space:]][$'\n']/:} 

The right way of removing duplicates suggested by @ghm1014 and @rush (in the comment) using sort:

PATH=`echo -e ${PATH//:/'\n'} | awk '{printf("%d|%s\n", NR, $0)}' | sort -t '|' -k 2 -u | sort -t '|' -k 1 -g | cut -f2 -d'|'`; export PATH=${PATH//[[:space:]]/:} 

The right way of removing duplicates suggested by @ghm1014 and @rush (in the comment) using sort:

PATH=`echo -e ${PATH//:/'\n'} | awk '{printf("%d|%s\n", NR, $0)}' | sort -t '|' -k 2 -u | sort -t '|' -k 1 -g | cut -f2 -d'|'`; export PATH=${PATH//[$'\n']/:} 
added 32 characters in body
Source Link
Varp
  • 11
  • 2

The right way of removing duplicates suggested by @ghm1014 and @rush (in the comment) using sort:

NEW_PATH=`echoPATH=`echo -e ${PATH//:/'\n'} | awk '{printf("%d|%s\n", NR, $0)}' | sort -t '|' -k 2 -u | sort -t '|' -k 1 -g | cut -f2 -d'|'`d'|'`; export PATH=${PATH//[[:space:]]/:} 

The right way of removing duplicates suggested by @ghm1014 and @rush (in the comment) using sort:

NEW_PATH=`echo -e ${PATH//:/'\n'} | awk '{printf("%d|%s\n", NR, $0)}' | sort -t '|' -k 2 -u | sort -t '|' -k 1 -g | cut -f2 -d'|'` 

The right way of removing duplicates suggested by @ghm1014 and @rush (in the comment) using sort:

PATH=`echo -e ${PATH//:/'\n'} | awk '{printf("%d|%s\n", NR, $0)}' | sort -t '|' -k 2 -u | sort -t '|' -k 1 -g | cut -f2 -d'|'`; export PATH=${PATH//[[:space:]]/:} 
Source Link
Varp
  • 11
  • 2

The right way of removing duplicates suggested by @ghm1014 and @rush (in the comment) using sort:

NEW_PATH=`echo -e ${PATH//:/'\n'} | awk '{printf("%d|%s\n", NR, $0)}' | sort -t '|' -k 2 -u | sort -t '|' -k 1 -g | cut -f2 -d'|'`