bug-bash
[Top][All Lists]
Advanced

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

Re: [feature request] parameter transformation to safely add strings to


From: Alex fxmbsw7 Ratchev
Subject: Re: [feature request] parameter transformation to safely add strings to PS1, &c.
Date: Mon, 23 Aug 2021 00:50:29 +0200

oh indeed it doesnt do what you want
maybe printf %q does
sorry

On Mon, Aug 23, 2021, 00:45 Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com> wrote:

> i meant this with removing quotes
>
> ~ $ shopt -s extglob ; a=( . a \' \$var $'\e[1m' ) ps='$ ' a=( "${a[@]@Q}"
> ) ; for i in ${!a[@]} ; do a[i]=${a[i]#?(\$)\'} a[i]=${a[i]%\'} ; done ;
> ps+=${a[*]} ; printf %s\\n "$ps"
> $ . a \ $var \E[1m
> ~ $
>
> On Mon, Aug 23, 2021, 00:02 Emanuele Torre <torreemanuele6@gmail.com>
> wrote:
>
>> Emanuele Torre <torreemanuele6@gmail.com> wrote:
>> >   ~ --${@Q}-> '~' --${#\'}-> ~' --${%\'}-> ~
>>
>> Sorry, that was a bad example. Still, it does not accomplish anything:
>>
>>   \w --${@Q}-> '\w' --${#\'}-> \w' --${%\'}-> \w
>>
>> On Sun, 22 Aug 2021 at 23:56, Emanuele Torre <torreemanuele6@gmail.com>
>> wrote:
>> >
>> > Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com> wrote:
>> > > and renoving the beginning and ending ' s
>> >
>> > even if you remove the first and last ':
>> > 1) that is 3 PEs as the solution i described (${a//\\/\\\\}
>> > ${a//\`/\\\`} ${a//$/\\$} vs ${a@Q} ${a#\'} ${a%\'} )
>> > 2) it doesn't actually accomplish anything:
>> >
>> >   ~ --${@Q}-> '~' --${#\'}-> ~' --${%\'}-> ~
>> >
>> > On Sun, 22 Aug 2021 at 23:14, Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
>> wrote:
>> > >
>> > > what about @Q
>> > > and renoving the beginning and ending ' s
>> > >
>> > >
>> > > On Sun, Aug 22, 2021, 23:13 Emanuele Torre <torreemanuele6@gmail.com>
>> wrote:
>> > >>
>> > >> It would be nice to have a parameter transformation (e.g. "${par@p
>> }")
>> > >> that expands $par to a string that will not be expanded by PS1, PS2,
>> &c.
>> > >>
>> > >> example:
>> > >>
>> > >>   tmp_var=$(blabla) # this variable will not exist when PS1 is
>> expanded
>> > >>   PS1="blabla ${tmp_var@p} blabla"
>> > >>
>> > >> I think a valid way to achieve the same behaviour in the currenct
>> > >> version of bash:
>> > >>
>> > >>   tmp_var=$(blabla)
>> > >>   tmp_var=${tmp_var//\\/\\\\}
>> > >>   tmp_var=${tmp_var//\`/\\\`}
>> > >>   tmp_var=${tmp_var//$/\\$}
>> > >>   PS1="blabla $tmp_var blabla"
>> > >>
>> > >> But a parameter transformation would be nicer.
>> > >>
>> > >> This parameter transformation should also make sure to not cause an
>> > >> expansion when concatenated.
>> > >>
>> > >>   var='$'
>> > >>   printf '%s\n' "${var@p}" # should not expand to `$'.
>> > >>   PS1="${var@P}(date)" # because this should expand to `$(date)'
>> > >>                        # and not to the output of `date'.
>> > >>
>> > >> Cheers,
>> > >>   emanuele6
>> > >>
>>
>


reply via email to

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