help-bash
[Top][All Lists]
Advanced

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

Re: PE with BASH_SOURCE doesnt seem to work


From: alex xmb sw ratchev
Subject: Re: PE with BASH_SOURCE doesnt seem to work
Date: Wed, 21 Feb 2024 08:27:06 +0100

On Wed, Feb 21, 2024, 08:20 Lawrence Velázquez <vq@larryv.me> wrote:

> On Wed, Feb 21, 2024, at 1:49 AM, alex xmb sw ratchev wrote:
> > i like do shorts , so i tried
> > the point is ' prepend PWD to BASH_SOURCE when it doesnt begin with a
> slash
> > '
> > but it doesnt seem working
> >
> > shopt -s extglob
> > f=${BASH_SOURCE/#!(/)*/$PWD/&}
> > declare -p f
> >
> > ~ $ bash tbash1
> > declare -- f="tbash1"
> >
> > ~ $ bash "$PWD/"tbash1
> > declare -- f="/data/data/com.termux/files/home/tbash1"
> >
> > the ' bash tbash1 ' case it is , it doesnt prepend anything
> > ( i also tried [!/] instead !(/) , same result )
>
> Bash uses the second unquoted "/" (or third, if you're using the
> // form) to separate the pattern and the replacement string.  To
> use "/" in the pattern itself, escape it.
>

aha , big thanks
i vote for proper decoding

        $ cat tbash1
>         shopt -s extglob
>
>         f=${BASH_SOURCE/#!(\/)*/$PWD/&}
>         g=${BASH_SOURCE/#[!\/]/$PWD/&}
>
>         declare -p f g
>
>         $ ./bash tbash1
>         declare -- f="/tmp/tbash1"
>         declare -- g="/tmp/tbash1"
>
> You should also quote $PWD in the replacement string, just in case
> it contains a "&".
>

will do , thanks
greets

        g=${BASH_SOURCE/#[!\/]/"$PWD"/&}
>
> --
> vq
>


reply via email to

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