#!/bin/bash
# Replace only first match - ${string/pattern/replacement}
filename="bash.string.txt"
echo "After Replacement:" ${filename/str*./operations.}
# After Replacement: bash.operations.txt
# Replace all the matches - ${string//pattern/replacement}
filename="Path of the bash is /bin/bash"
echo "After Replacement:" ${filename//bash/sh}
# After Replacement: Path of the sh is /bin/sh
# Replace only beginning of string - ${string/#pattern/replacement
# Replace only end of string - ${string/%pattern/replacement
filename="/root/admin/monitoring/process.sh"
echo "Replaced at the beginning:" ${filename/#\/root/\/tmp}
# Replaced at the beginning: /tmp/admin/monitoring/process.sh
echo "Replaced at the end": ${filename/%.*/.ksh}
# Replaced at the end: /root/admin/monitoring/process.ksh