How to keep from duplicating path variable in ksh

2019-07-16 02:04发布

问题:

Similar question to How to keep from duplicating path variable in csh. But I don't use csh.

PATH=${SOMETHING}:${PATH}

How do I remove duplicates from PATH.

回答1:

I use this oneliner, but it depends on gawk.

PATH=$(echo $PATH|tr ":" "\n"|gawk '!($0 in a) { a[$0];print}'|paste -sd: - )


标签: path ksh