source: vendor/bash/3.1-p17/examples/functions/dirname

Last change on this file was 3228, checked in by bird, 18 years ago

bash 3.1

File size: 573 bytes
Line 
1# Date: Fri, 11 Oct 91 11:22:36 edt
2# From: friedman@gnu.ai.mit.edu
3# To: bfox@gnu.ai.mit.edu
4
5# A replacement for dirname(1). This one appears less often on some
6# systems I use than basename(1), and I really depend on it for some
7# things. Usage: dirname [path]
8function dirname ()
9{
10 local dir="$1"
11 local tdir="${dir%/}"
12
13 # Strip trailing '/' characters from dir (unusual that this should
14 # ever occur, but dirname(1) seems to deal with it.)
15 while [ "${tdir}" != "${dir}" ]; do
16 tdir="${dir}"
17 dir="${tdir%/}"
18 done
19
20 echo "${dir%/*}"
21}
Note: See TracBrowser for help on using the repository browser.