#!/bin/bash ## POSIX compliant function to replace basename # derived from ShellDorado _basename() { fn_path=$1 fn_suffix=$2 case $fn_path in ## The spec says: "If string is a null string, it is ## unspecified whether the resulting string is '.' or a ## null string. This implementation returns a null string "") return ;; *) ## strip trailing slashes while : do case $fn_path in */) fn_path=${fn_path%/} ;; *) break ;; esac done case $fn_path in "") fn_path="/" ;; *) fn_path=${fn_path##*/} ;; esac ;; esac case $fn_path in $fn_suffix | "/" ) _BASENAME="$fn_path" ;; *) _BASENAME=${fn_path%$fn_suffix} esac } _basename "$@" && printf "%s\n" "$_BASENAME"