help-bash
[Top][All Lists]
Advanced

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

Re: small problem with BASH_SOURCE and PATH


From: Alex fxmbsw7 Ratchev
Subject: Re: small problem with BASH_SOURCE and PATH
Date: Fri, 11 Feb 2022 22:24:46 +0100

On Fri, Feb 11, 2022 at 10:04 PM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
wrote:

>
> On Fri, Feb 11, 2022 at 8:40 PM Dennis Williamson <
> dennistwilliamson@gmail.com> wrote:
>
>>
>>
>> On Fri, Feb 11, 2022, 12:57 PM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
>> wrote:
>>
>>> function absolutebasepath() {
>>>
>>> declare arg t=
>>>
>>> for arg; do
>>> if [[ ${t:=$arg} != /* ]]; then
>>> if [[ $t == */* ]]; then
>>> r=$PWD/${t%/*}; else
>>> r=$PWD/.; fi; else
>>> r=${t%/*}; fi
>>> absolutebasepath+=( "$r" )
>>> done
>>>
>>> }
>>>
>>> i post this in hopes for others
>>> it returns ( in an array ) its args as aboslute base paths
>>> useful for 'where script is'
>>>
>>> absolutebasepath "$BASH_SOURCE"
>>> printf 'script is in %s\n' "$absolutebasepath"
>>>
>>> ( multiple runs multiple elements )
>>>
>>> ${absolutebasepath[0]} is default and if ran multiple then [1] [2] etc
>>>
>>> ill hopefully code an assignments only variant and post it, maybe with
>>> benchmarks
>>>
>>
>> http://mywiki.wooledge.org/BashFAQ/028
>>
>
> err from the page
>

greg, consider overhaulting your whole page, or it gets marked as invalid
as the others by me

>
> bash stup ; cat stup
> stup: line 1: cd: stup/: Not a directory
> /root
> cd "${BASH_SOURCE%/*}/"
> pwd
>
> besides, this page sadly is not more than invalid just like the others
>
> wait for mine
>
>>
>> Also please learn to properly indent your code.
>>
> i do so, this is new style, too bad indent means tab to you
>
>>
>> And while many people put then at the end of the if line, you should put
>> else at the beginning of a line or on a line by itself. And fi should be on
>> a line by itself.
>>
>> Putting ${t:=$arg} inside an if is bad practice.
>>
> what the nonsense
>


reply via email to

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