Excerpts from Amadeusz Żołnowski's message of Wed Oct 13 21:20:01 +0200 2010:
> Excerpts from Mike Frysinger's message of Wed Oct 13 20:51:35 +0200 2010:
> > path_exists() {
> >     local opt=$1
> >     [[ ${opt} == -[ao] ]] && shift || opt="-a"
> > 
> >     # no paths -> return false
> >     # same behavior as: [[ -e "" ]]
> >     [[ $# -eq 0 ]] && return 1
> > 
> >     local p r=0
> >     for p in "$@" ; do
> >         [[ -e ${p} ]]
> >         : $(( r += $? ))
> >     done
> 
> 1) Why check every path in both "and" and "or" cases?
> 
> 2) Even simpler:
> for p; do
>   [[ -e $p ]]
>   ((r+=$?))
> done
> 
> > 
> >     case ${opt} in
> >         -a) return $(( r != 0 )) ;;
> >         -o) return $(( r == $# )) ;;
> >     esac
> > }


And why putting different tasks into one function?  My suggestion:

any_paths() {
    local f

    for f; do
        [[ -e $f ]] && return 0
    done

    return 1
}

all_paths() {
    local f

    for f; do
        [[ -e $f ]] || return 1
    done

    return 0
}


Isn't it simpler approach?  And have benfits over 2in1:

1) More readable in use.
2) More efficient.
3) 1 + 1 < 2 in this case ;-)
-- 
Amadeusz Żołnowski

PGP key fpr: C700 CEDE 0C18 212E 49DA  4653 F013 4531 E1DB FAB5

Attachment: signature.asc
Description: PGP signature

Reply via email to