[-- Attachment #1: Type: text/plain, Size: 351 bytes --] Hello, I have something like a=('aa bb' 'cc dd'); and I would like to get the quoted representation inside a string, so that echo -e $b 'aa bb' 'cc dd' or that typeset -p b gives '''aa bb'' ''cc dd''' I tried with a=(sa\ bb cc\ dd); b="${(q+)a[@]}"; typeset -p b typeset b='''sa bb cc dd''' and other inconclusive variations Pier Paolo Grassi [-- Attachment #2: Type: text/html, Size: 896 bytes --]
[-- Attachment #1: Type: text/plain, Size: 664 bytes --] I think I found a way a=(sa\ bb cc\ dd); a=${(qq@)"${a[@]}"}; typeset -p a; echo -e $a typeset a='''sa bb'' ''cc dd''' 'sa bb' 'cc dd' sorry for the bother Pier Paolo Grassi Il giorno mar 28 set 2021 alle ore 13:35 Pier Paolo Grassi < pierpaolog@gmail.com> ha scritto: > Hello, I have something like > a=('aa bb' 'cc dd'); > > and I would like to get the quoted representation inside a string, so that > > echo -e $b > 'aa bb' 'cc dd' > > or that > > typeset -p b > gives > '''aa bb'' ''cc dd''' > > I tried with > > a=(sa\ bb cc\ dd); b="${(q+)a[@]}"; typeset -p b > typeset b='''sa bb cc dd''' > > and other inconclusive variations > > Pier Paolo Grassi > [-- Attachment #2: Type: text/html, Size: 1710 bytes --]
hello, echo $ZSH_VERSION omz=( 'the first' 'the last' ) echo a isa ${(t)omz} typeset -p omz echo -e "${(@qq)omz}" gives me 5.8 a isa array typeset -a omz=( 'the first' 'the last' ) 'the first' 'the last' note the -a when you have typeset a='''sa bb'' ''cc dd''' so ${(t)omz} is probably scalar. would you mind unset a and give my code a try ? regards marc
On Tue, Sep 28, 2021 at 4:39 AM Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
>
> a=(sa\ bb cc\ dd); a=${(qq@)"${a[@]}"}; typeset -p a; echo -e $a
It should be sufficient to do
a=${(qqq)a}
[-- Attachment #1: Type: text/plain, Size: 417 bytes --] on 5-8 I get: > a=(sa\ bb cc\ dd); a=${(qqq)a} > typeset -p a typeset a='"sa bb cc dd"' Pier Paolo Grassi Il giorno mar 28 set 2021 alle ore 18:04 Bart Schaefer < schaefer@brasslantern.com> ha scritto: > On Tue, Sep 28, 2021 at 4:39 AM Pier Paolo Grassi <pierpaolog@gmail.com> > wrote: > > > > a=(sa\ bb cc\ dd); a=${(qq@)"${a[@]}"}; typeset -p a; echo -e $a > > It should be sufficient to do > > a=${(qqq)a} > [-- Attachment #2: Type: text/html, Size: 1104 bytes --]
On Tue, Sep 28, 2021, at 3:54 PM, Pier Paolo Grassi wrote:
> on 5-8 I get:
>
>> a=(sa\ bb cc\ dd); a=${(qqq)a}
>> typeset -p a
> typeset a='"sa bb cc dd"'
Perhaps it should have been ${(qqq@)a}?
% a=(sa\ bb cc\ dd); typeset -p a
typeset -a a=( 'sa bb' 'cc dd' )
% b=${(qqq@)a}; typeset -p b
typeset b='"sa bb" "cc dd"'
--
vq
[-- Attachment #1: Type: text/plain, Size: 878 bytes --] Hello, here is the output: 5.8 a isa array typeset -a omz=( 'the first' 'the last' ) 'the first' 'the last' the result from your script is in fact correct if I assign the "${(@qq)omz}": typeset -a omz=( 'the first' 'the last' ) a="${(@qq)omz}" typeset -p a typeset a='''the first'' ''the last''' regards Pier Paolo Grassi Il giorno mar 28 set 2021 alle ore 20:31 Marc Chantreux < mc@prometheus.u-strasbg.fr> ha scritto: > hello, > > echo $ZSH_VERSION > omz=( 'the first' 'the last' ) > echo a isa ${(t)omz} > typeset -p omz > echo -e "${(@qq)omz}" > > gives me > > 5.8 > a isa array > typeset -a omz=( 'the first' 'the last' ) > 'the first' 'the last' > > note the -a when you have > > typeset a='''sa bb'' ''cc dd''' > > so ${(t)omz} is probably scalar. would you mind unset a and give > my code a try ? > > regards > marc > > > [-- Attachment #2: Type: text/html, Size: 1835 bytes --]
[-- Attachment #1: Type: text/plain, Size: 595 bytes --] yes this works fine: a=(sa\ bb cc\ dd); a=${(qqq@)a}; typeset -p a typeset a='"sa bb" "cc dd"' Pier Paolo Grassi Il giorno mar 28 set 2021 alle ore 22:09 Lawrence Velázquez <larryv@zsh.org> ha scritto: > On Tue, Sep 28, 2021, at 3:54 PM, Pier Paolo Grassi wrote: > > on 5-8 I get: > > > >> a=(sa\ bb cc\ dd); a=${(qqq)a} > >> typeset -p a > > typeset a='"sa bb cc dd"' > > Perhaps it should have been ${(qqq@)a}? > > % a=(sa\ bb cc\ dd); typeset -p a > typeset -a a=( 'sa bb' 'cc dd' ) > % b=${(qqq@)a}; typeset -p b > typeset b='"sa bb" "cc dd"' > > -- > vq > [-- Attachment #2: Type: text/html, Size: 1259 bytes --]
On Tue, Sep 28, 2021 at 1:09 PM Lawrence Velázquez <larryv@zsh.org> wrote:
>
> Perhaps it should have been ${(qqq@)a}?
Yes, typo on my part, sorry.