Below is my questions
RELEASE_BRANCH=5.2.2
echo $RELEASE_BRANCH | sed 's/\./\\./g'
5\.2\.2
RELEASE=`echo $RELEASE_BRANCH|sed 's/\./\\./g'`
echo $RELEASE
5.2.2
What I am expecting
echo $RELEASE
5\.2\.2
Any ideas?
Use of back-ticks is deprecated. You should use command substitution instead.
#!/bin/bash
RELEASE_BRANCH=5.2.2
RELEASE=$(echo $RELEASE_BRANCH|sed 's/\./\\./g')
echo "$RELEASE"
Note: Please read the Important differences (bullet 1) from the link for more details.
We seldom think about the powerful string-manipulation functions made available by bash, and in this case the following works very well:
${string/substring/replacement}
Replace first match of $substring with $replacement.${string//substring/replacement}
Replace all matches of $substring with $replacement.
So here we are going to use the second version, to have a neat one-liner:
$ RELEASE_BRANCH=5.2.2
$ echo ${RELEASE_BRANCH//./\\.}
5\.2\.2
's/\./\\\\./g'?