bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: weird problem -- path interpretted/eval'd as numeric expression


From: John Kearney
Subject: Re: weird problem -- path interpretted/eval'd as numeric expression
Date: Fri, 29 Mar 2013 15:11:07 +0100
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130307 Thunderbird/17.0.4

Am 29.03.2013 12:57, schrieb Greg Wooledge:
> On Fri, Mar 29, 2013 at 12:41:46AM -0700, Linda Walsh wrote:
>>      include was designed to search the path for functions that
>> are relative paths.  While the normal sourcepath allows searching for
>> filenames on the search path, I don't believe (please correct if I am wrong
>> and this works now, as it would make life much simpler) that the PATH will
>> be searched if you give it something like:
>>
>> source lib/Util/sourcefile.shh
> Is that all you want?  Here:
>
> include() {
>     local paths dir
>     IFS=: read -ra paths <<< "$PATH"
>     for dir in "${paths[@]}"; do
>       if [[ -r $dir/$1 ]]; then
>           source "$dir/$1"
>           return
>       fi
>     done
>     echo "could not find '$1' in PATH" >&2
>     return 1
> }
>
Actually I've had trouble

IFS=: read -ra paths <<< "$PATH"

and embedded new lines.

I think this is better
find_file() {
    local IFS=:
    for dir in $PATH; do
        [[ ! -r $dir/$1 ]] || continue
        FOUND_FILE="$dir/$1"
        return 0
    done
    echo "could not find '$1' in PATH" >&2
    return 1
}
include() {
    local FOUND_FILE
    find_file "${1:?Missing File Name }" || return $?
    source "${FOUND_FILE}"
}
includeExt() {
    local FOUND_FILE
    local PATH=${1:?Missing Search Path}
    find_file "${2:?Missing File Name}" || return $?
    source "${FOUND_FILE}"
}

Ideally what I want to do is
alias include=source\ "$(find_file "${1}")"
but that doesn't work in bash and I still haven't found a way around the
problem.


The only way I can think to do it is to use a second file.

cat <<EOF ><known_path>/source_wrapper.sh
    find_file "${1:?Missing File Name }" || return $?
    source "${FOUND_FILE}"
EOF
alias include=source\ "<known_path>/source_wrapper.sh"


cheers









reply via email to

[Prev in Thread] Current Thread [Next in Thread]