#!/bin/bash

## (c) Carlos Duarte ## Created: 09-Sep-96 ## Updated: - ##

# usage: fbasename file  
# or
# usage: find path -print | fbasename
# 
# 
# this is a basename, but read filenames from stdin, each line
# contains the path and a possible suffix
# 
# this will produce one output line per input line, with 
# the filename component of path, with the (possible) suffix
# removed

## Modified by Steven Shiau <steven _at_ nchc org tw> so that the interpreter is /bin/sh, since different distributions put sed in different PATH, like /bin or /usr/bin

sed -e "
s/^[ 	]*//
s/[ 	]*$//

tc
:c

s/[ 	][ 	]*/\
/
ta

s/\/*$//
s/.*\///
b

:a

h
s/.*\n//
x
s/\n.*//

s/\/*$//
s/.*\///

tb
:b
G
s/^\(.*\)\(.*\)\n\2$/\1/
t

P
d
"
