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 19:55:48 +0100

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


reply via email to

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