How to replace placeholder character or word in variable with value from another variable in Bash?

后端 未结 8 2113
死守一世寂寞
死守一世寂寞 2020-12-08 14:01

I\'m trying to write a simple Bash script. I have a simple \"template\" variable:

template = \"my*appserver\"

I then have a function (

8条回答
  •  没有蜡笔的小新
    2020-12-08 14:23

    Yeah, either 'sed' as the others have said, or start with your template in 2 separate variables and construct on the fly. e.g.

    templateprefix="my"
    templatesuffix="appserver"
    
    server=get_env
    
    template=${templateprefix}${server}${templatesuffix}
    

提交回复
热议问题