In this question
@SiegeX gives a nice way of cleaning the bash PATH variable from duplicate entr开发者_Python百科ies:
PATH=$(awk 'BEGIN{ORS=":";RS="[:\n]"}!a[$0]++' <<<"${PATH%:}")
this works well when I type it in the command line. I tried using this in a bash function to be able to apply it to other variables:
function dupremove()
{
${1}=$(awk 'BEGIN{ORS=":";RS="[:\n]"}!a[$0]++' <<<"${1%:}")
}
but when I execute it it gives the error:
> dupremove PATH
bash: PATH=PATH:: command not found
Any idea on I can write the function?
This works for me (TM)
function dupremove
{
eval path=\$$1
export $1=$(awk 'BEGIN{ORS=":";RS="[:\n]"}!a[$0]++' <<< $path)
}
精彩评论