开发者

command working in command line but cannot generalize as function

开发者 https://www.devze.com 2023-03-23 00:16 出处:网络
In this question @SiegeX gives a nice way of cleaning the bash PATH variable from duplicate entr开发者_Python百科ies:

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)
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号