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

Bash can do string replacement by itself:

template="my*appserver"
server="live"
template="${template/\*/$server}"

See the advanced bash scripting guide for more details on string replacement.

So for a bash function:

function string_replace {
    echo "${1/\*/$2}"
}

And to use:

template=$(string_replace "$template" "$server")

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)