Bash Substitution Replace

[Solved] Bash Substitution Replace | Shell - Code Explorer | yomemimo.com
Question : bash substitution replace

Answered by : jason-m-potter

## Bash Substitution - Search/Replace
${var#Pattern}
# Remove the shortest part of $Pattern that matches the front end of $var.
${var##Pattern}
# Remove the longest part of $Pattern that matches the front end of $var.
${var%Pattern}
# Remove the shortest part of $Pattern that matches the back end of $var
${var%%Pattern}
# Remove the longest part of $Pattern that matches the back end of $var
${var/Pattern/Replacement}
# Replace First match of Pattern
# If Replacement is omitted, the first match is replaced by nothing
${var//Pattern/Replacement}
# Global replacement. Replace All matches of Pattern
# if Replacement omitted, all occurrences of Pattern are replaced by nothing

Source : https://tldp.org/LDP/abs/html/parameter-substitution.html | Last Update : Wed, 28 Sep 22

Answers related to bash substitution replace

Code Explorer Popular Question For Shell