Created
December 16, 2015 03:50
Bash pattern matching samples
This file contains hidden or 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
#!/bin/bash | |
FILE=/home/user/src/prog.c | |
echo ${FILE#/*/} # ==> user/src/prog.c | |
echo ${FILE##/*/} # ==> prog.c | |
echo ${FILE%/*} # ==> /home/user/src | |
echo ${FILE%%/*} # ==> nil | |
echo ${FILE%.c} # ==> /home/user/src/prog | |
# All this from the excellent book: "A Practical Guide to Linux Commands, Editors, and | |
# Shell Programming by Mark G. Sobell (http://www.sobell.com/) | |
# found here: http://stackoverflow.com/questions/1199613/extract-filename-and-path-from-url-in-bash-script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment