diff options
author | cvpcs <root@cvpcs.org> | 2010-06-02 11:02:31 -0500 |
---|---|---|
committer | cvpcs <root@cvpcs.org> | 2010-06-02 11:02:31 -0500 |
commit | 772f20abb0a3a0979c440114bf3a1cff5b3cef03 (patch) | |
tree | 3384b9291d73a12542c526a8557218c7435491b0 /examples/functions/basename2 | |
download | external_bash-772f20abb0a3a0979c440114bf3a1cff5b3cef03.zip external_bash-772f20abb0a3a0979c440114bf3a1cff5b3cef03.tar.gz external_bash-772f20abb0a3a0979c440114bf3a1cff5b3cef03.tar.bz2 |
initial import of bash 4.1
Diffstat (limited to 'examples/functions/basename2')
-rw-r--r-- | examples/functions/basename2 | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/functions/basename2 b/examples/functions/basename2 new file mode 100644 index 0000000..a42231c --- /dev/null +++ b/examples/functions/basename2 @@ -0,0 +1,43 @@ +#From: "Grigoriy Strokin" <grg@philol.msu.ru> +#Newsgroups: comp.unix.shell +#Subject: fast basename and dirname functions for BASH/SH +#Date: Sat, 27 Dec 1997 21:18:40 +0300 +# +#Please send your comments to grg@philol.msu.ru + +function basename() +{ + local name="${1##*/}" + echo "${name%$2}" +} + +function dirname() +{ + local dir="${1%${1##*/}}" + [ "${dir:=./}" != "/" ] && dir="${dir%?}" + echo "$dir" +} + +# Two additional functions: +# 1) namename prints the basename without extension +# 2) ext prints extension of a file, including "." + +function namename() +{ + local name=${1##*/} + local name0="${name%.*}" + echo "${name0:-$name}" +} +function ext() +{ + local name=${1##*/} + local name0="${name%.*}" + local ext=${name0:+${name#$name0}} + echo "${ext:-.}" +} + + + + + + |