将sed的结果存储到变量中

时间:2016-08-22 18:37:21

标签: bash

我有以下代码......它主要是工作。除了我想将sed的结果写入变量newData。查看了很多其他帖子,但没有人能够为我工作。

newin="<font color='default'>Default Color has been choosen.</font>"

newData="$newin" | sed 's/&lt;/</g; s/&gt;/>/g; s/<[^>]*>//g'

if [[ ${newin:0:1} == "<" ]]
then

    #this echo works like it should
    echo "$newin" | sed 's/&lt;/</g; s/&gt;/>/g; s/<[^>]*>//g'

    #this echo works like it should

    echo "$newin"

    #The variable newData does not seem to capture the data
    newData=${newin} | sed 's/&lt;/</g; s/&gt;/>/g; s/<[^>]*>//g'
    echo "[$newdata]"

fi

输出:

Default Color has been choosen.
<font color='default'>Default Color has been choosen.</font>
[]

0 个答案:

没有答案