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: Linda Walsh
Subject: Re: weird problem -- path interpretted/eval'd as numeric expression
Date: Fri, 29 Mar 2013 20:21:21 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.24) Gecko/20100228 Lightning/0.9 Thunderbird/2.0.0.24 Mnenhy/0.7.6.666


John Kearney wrote:
> Am 29.03.2013 18:53, schrieb Linda Walsh:
>> Greg Wooledge wrote:
>>> 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
>>> }
>> ------
>> It  also doesn't keep track of the previously sourced files so as to
>> not 're-source' them if one of the files you 'source' also sources a file.
>>
>> It also allows one to optionally leave off the extension, but other than
>> those additions... yeah... that's close...
>>
>> The idea is *mainly* to be able to read in functions and aliases..
>>
>> Vars expected to 'survive' for those funcs or aliases are exported...but
>> that may not be enough to get them out of the local context...not sure.
>>
> 
> Like this then ?
> 
> unset INCLUDED ; 
> declare -A INCLUDED
> find_file() {
>     local dir 
>     FOUND_FILE=""
>     [ $((INCLUDED[${1%.sh}]+=1)) -eq 1 ] || return 1
>     while IFS= read -rd ':' dir ;do
>       #echo "trying : ${dir}/${1%.sh}.sh"
>         [[ -r ${dir}/${1%.sh}.sh ]] || continue
>         FOUND_FILE="${dir}/${1%.sh}.sh"
>       echo "found : ${FOUND_FILE}"
>     done <<< "${PATH}"
>     [ -n "${FOUND_FILE:-}" ] || echo "could not find '$1' in PATH" >&2
>     return ${FOUND_FILE+1}
> } && echo 'find_file "${1:?Missing File Name }" && source "${FOUND_FILE}"' 
> >/tmp/source_wrapper.sh && alias include=source\ "/tmp/source_wrapper.sh"
> 
> 
> I actually tested this one and it seems to work ok.
---
I'll have to drop it in and see what happens! Always one for experimenting! ;-)



reply via email to

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