Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

bash substitution

## 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 by tldp.org #
 
PREVIOUS NEXT
Tagged: #bash #substitution
ADD COMMENT
Topic
Name
6+9 =