[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [feature request] parameter transformation to safely add strings to
From: |
Emanuele Torre |
Subject: |
Re: [feature request] parameter transformation to safely add strings to PS1, &c. |
Date: |
Sun, 22 Aug 2021 23:38:48 +0200 |
That is not at all the same thing.
$ t='~' q='?' s='*' n=$'\n' bn='\n'
$ a="hello ${t@Q} ${q@Q} ${s@Q} ${n@Q} ${bn@Q} hi"
$ printf '%s\n' "${a@P}"
hello '~' '?' '*' $'
' '
' hi
With the parameter transformation I requested, this is what should be printed:
$ t='~' q='?' s='*' n=$'\n' bn='\n'
$ a="hello ${t@p} ${q@p} ${s@p} ${n@P} ${bn@p} hi"
$ printf '%s\n' "${a@P}"
hello ~ ? *
\n hi
Similarly to the sequence of PEs i described previously (which I'm not
sure is actually bullet proof;kj this is also one reason why it would be
nice to have a dedicated parameter transformation that is guaranteed to
work):
$ t='~' q='?' s='*' n=$'\n' bn='\n'
$ s_t=${t//\\/\\\\} s_t=${s_t//\`/\\\`} s_t=${s_t/$/\\$}
$ s_q=${q//\\/\\\\} s_q=${s_q//\`/\\\`} s_q=${s_q/$/\\$}
$ s_s=${s//\\/\\\\} s_s=${s_s//\`/\\\`} s_s=${s_s/$/\\$}
$ s_n=${n//\\/\\\\} s_n=${s_n//\`/\\\`} s_n=${s_n/$/\\$}
$ s_bn=${bn//\\/\\\\} s_bn=${s_bn//\`/\\\`} s_bn=${s_bn/$/\\$}
$ a="hello $s_t $s_q $s_s $s_n $s_bn hi"
$ printf '%s\n' "${a@P}"
hello ~ ? *
\n hi
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
>>
- [feature request] parameter transformation to safely add strings to PS1, &c., Emanuele Torre, 2021/08/22
- Re: [feature request] parameter transformation to safely add strings to PS1, &c., Alex fxmbsw7 Ratchev, 2021/08/22
- Re: [feature request] parameter transformation to safely add strings to PS1, &c.,
Emanuele Torre <=
- Re: [feature request] parameter transformation to safely add strings to PS1, &c., Emanuele Torre, 2021/08/22
- Re: [feature request] parameter transformation to safely add strings to PS1, &c., Emanuele Torre, 2021/08/22
- Re: [feature request] parameter transformation to safely add strings to PS1, &c., Alex fxmbsw7 Ratchev, 2021/08/22
- Re: [feature request] parameter transformation to safely add strings to PS1, &c., Alex fxmbsw7 Ratchev, 2021/08/22
- Re: [feature request] parameter transformation to safely add strings to PS1, &c., Alex fxmbsw7 Ratchev, 2021/08/22
Re: [feature request] parameter transformation to safely add strings to PS1, &c., Koichi Murase, 2021/08/22
Re: [feature request] parameter transformation to safely add strings to PS1, &c., Chet Ramey, 2021/08/23