Shell features you didn't know you needed (or possibly even existed) #9
Source: Dev.to
Replacing / in a Git branch name for Docker tags
When converting a Git branch name like // into a Docker image tag, the / characters must be removed or replaced because Docker tags cannot contain /.
Using tr
IMAGE_TAG=$(echo "$BRANCH" | tr '/' '-')Using sed
IMAGE_TAG=$(echo "$BRANCH" | sed -e 's/\//-/g')Using perl
IMAGE_TAG=$(echo "$BRANCH" | perl -pe 's/\//-/g')Using Bash parameter expansion
IMAGE_TAG=${BRANCH//\//-}${VARIABLE/from/to}replaces the first occurrence offromwithto.${VARIABLE//from/to}replaces all occurrences offromwithto.