csh variable modifiers in bash
csh and zsh have handy variable modifiers to handle paths and filenames. Here are the bash versions:
mypath=/foo/bar/baz.sh
myfile=baz.sh
*in csh: *
$ echo ${mypath:h}
/foo/bar
$ echo ${mypath:t}
baz.sh
$ echo ${myfile:r}
baz
$ echo ${myfile:e}
sh
*in bash: *
$ echo ${mypath%/*}
/foo/bar
$ echo ${mypath##*/}
baz.sh
$ echo ${myfile%.*}
baz
$ echo ${myfile##*.}
sh
Written by Dustin Morado
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#