Skip to content

Instantly share code, notes, and snippets.

@Error601
Created December 16, 2015 03:50
Show Gist options
  • Save Error601/cc1d1704336440c319e4 to your computer and use it in GitHub Desktop.
Save Error601/cc1d1704336440c319e4 to your computer and use it in GitHub Desktop.
Bash pattern matching samples
#!/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