in reply to Perl one-liner to remove duplicate entries from PATH

Well it seems to me that you do have a working solution and to add to the other answers you got:

However be warned: I'm now more playing golf than answering your actual question...


Comment on Re: Perl one-liner to remove duplicate entries from PATH
Select or Download Code
Re^2: Perl one-liner to remove duplicate entries from PATH
by sfink (Deacon) on Jan 12, 2006 at 18:09 UTC
    Or a variant using colon-terminated lines rather than colon-separated fields, allowing the uniqueness code itself to be very straightforward:
    MYPATH=$(echo -n "$PATH"|perl -072 -lne 'print unless $s{$_}++')
    (octal 072 is ":", the colon character)

    Because this is interpreting the entries in $PATH as colon-terminated rather than colon-separated, though, this will tack on an unwanted colon at the end.

    So the full solution wouldn't be as pretty. You'd need something like:

    MYPATH=$(echo -n "$PATH"|perl -072 -lne 'print unless $s{$_}++') MYPATH="${MYPATH%:}"