:
# RCSid:
#	$Id: exists.sh,v 1.9 2026/07/01 00:40:16 sjg Exp $
#			
#	@(#) Copyright (c) 1999-2026 Simon J. Gerraty
#
#	SPDX-License-Identifier: BSD-2-Clause
#      
#	Please send copies of changes and bug-fixes to:
#	sjg@crufty.net
#

_EXISTS_SH=:

Exists() {
    eval ${_local:-:} _af _bf _ls _rc _t
    _af=
    _bf=:
    _ls=
    : -=$-
    case "$-" in
    *e*) _rc=${Exists_default_rc:-0};; # default avoids issues with set -e
    *)   _rc=1;;
    esac
    _t=-s
    while :
    do
        case "$1" in
        --all) _af=:; shift;;
        --bf) _rc=1 _bf=; shift;; # caller expects failure
        --lt) _ls=t; shift;;
        --lr|--ltr) _ls=tr; shift;;
        -?) _t=$1; shift;;
        *) break;;
        esac
    done
    if test x$_ls != x; then
        case "$_t" in
        -d) _ls=d$_ls;;
        esac
        set -- `'ls' -1$_ls "$@" 2> /dev/null`
    fi
    for f in "$@"
    do
        test $_t $f || continue
        _rc=0
        $_bf break
        echo $f
        $_af break
    done
    return $_rc
}

case /$0 in
*/exist*) Exists "$@";;
esac

