Last active
August 29, 2015 14:15
-
-
Save hsuh/f08c526c9c39e9646357 to your computer and use it in GitHub Desktop.
Bash pattern matching
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
$ a=/cygdrive/c/projects/sandbox/projects | |
##match pattern from the left hand side. Double # means greedy. | |
hsuh@hsuh /cygdrive/c/projects/sandbox/projects | |
$ echo ${a##*sandbox} | |
/projects | |
##match pattern from the right hand side. Double % means greedy. | |
hsuh@hsuh /cygdrive/c/projects/sandbox/projects | |
$ echo ${a%%proj*} | |
/cygdrive/c/ | |
##match pattern from the right hand side. Remove the matched pattern. Return the rest. | |
hsuh@hsuh /cygdrive/c/projects/sandbox/projects | |
$ echo ${a%proj*} | |
/cygdrive/c/projects/sandbox/ | |
More awesomeness here - http://www.tldp.org/LDP/abs/html/parameter-substitution.html | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment