[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: PE with BASH_SOURCE doesnt seem to work
From: |
Lawrence Velázquez |
Subject: |
Re: PE with BASH_SOURCE doesnt seem to work |
Date: |
Wed, 21 Feb 2024 02:19:48 -0500 |
User-agent: |
Cyrus-JMAP/3.11.0-alpha0-153-g7e3bb84806-fm-20240215.007-g7e3bb848 |
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.
$ 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 "&".
g=${BASH_SOURCE/#[!\/]/"$PWD"/&}
--
vq