问题
I am working with a script that has a variable called PRODUCT_VERSION
.
The version comes with a dot (for example 6.0
).
I need to remove the dot and save the result in another variable.
So far I come with this, but it does not work correctly
PRD_VER=$(sed "s/$PRODUCT_VERSION/\.//g")
回答1:
$ PRODUCT_VERSION=6.0
$ PRD_VER=${PRODUCT_VERSION/.}
$ echo $PRD_VER
60
Bash String Manipulation Examples
回答2:
This might work for you (GNU sed & bash):
NEW=$(sed 's/\.//g' <<<"$OLD")
or
NEW=$(echo "$OLD" | sed 's/\.//g')
However Mr Penny's answer is by far the best approach.
来源:https://stackoverflow.com/questions/16048316/delete-pattern-from-a-variable-with-sed