Last active
May 18, 2016 04:25
-
-
Save bryder/6818b6fb4b08a847ed09f4b063a9c225 to your computer and use it in GitHub Desktop.
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
Reference: http://tldp.org/LDP/LG/issue18/bash.html | |
Given: | |
foo=/tmp/my.dir/filename.tar.gz | |
We can use these expressions: | |
path = ${foo%/*} | |
To get: /tmp/my.dir (like dirname) | |
file = ${foo##*/} | |
To get: filename.tar.gz (like basename) | |
base = ${file%%.*} | |
To get: filename | |
ext = ${file#*.} | |
To get: tar.gz | |
Note that the last two depend on the assignment made in the second one | |
if you want to get | |
/one/two/three/four.blah | |
and turn it into | |
/one/two | |
you can | |
i=/one/two/three/four.blah | |
echo ${i%/*/*} | |
/one/two |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment