26 lines
958 B
Bash
Executable File
26 lines
958 B
Bash
Executable File
#! /bin/sh
|
|
# Copyright (c) 1984 AT&T
|
|
# All Rights Reserved
|
|
|
|
# THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
|
|
# The copyright notice above does not evidence any
|
|
# actual or intended publication of such source code.
|
|
|
|
#ident "@(#)basename:basename.sh 1.7"
|
|
#ident "$Header: /proj/irix6.5.7m/isms/eoe/cmd/basename/RCS/basename.sh,v 1.1 1993/07/15 21:55:38 wtk Exp $"
|
|
if [ $# -gt 2 ]
|
|
then
|
|
echo >&2 "Usage: basename [ path [ suffix-pattern ] ]"
|
|
exit 1
|
|
fi
|
|
# If no first argument or first argument is null, make first argument
|
|
# "." Add beginning slash, then remove trailing slashes, then remove
|
|
# everything up through last slash, then remove suffix pattern if
|
|
# second argument is present.
|
|
# If nothing is left, first argument must be of form //*, in which
|
|
# case the basename is /.
|
|
exec /bin/expr \
|
|
"/${1:-.}" : '\(.*[^/]\)/*$' : '.*/\(..*\)' : "\\(.*\\)$2\$" \| \
|
|
"/${1:-.}" : '\(.*[^/]\)/*$' : '.*/\(..*\)' \| \
|
|
"/${1:-.}" : '.*/\(..*\)'
|