Created
April 24, 2012 18:44
-
-
Save caruccio/2482538 to your computer and use it in GitHub Desktop.
Pattern substitution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ VAR='XOXOXOX' | |
$ echo ${VAR/X/.} ## first occurence only (anywhere) | |
.OXOXOX | |
$ echo ${VAR//X/.} ## all occurences | |
.O.O.O. | |
$ VAR='OXOXOX' | |
$ echo ${VAR/#X/.} ## first occurence (only if beginning match) | |
OXOXOX | |
$ VAR='XOXOXO' | |
$ echo ${VAR/$X/.} ## first occurence (only if ending match) | |
XOXOXO | |
## Real file example: | |
# printf-style value substituition | |
$ file='/some/path' | |
$ format='cat %f' | |
$ echo ${format//%f/$file} | |
cat /some/path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment