Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: field splitting



doesn't seem to work

line="abcd"
echo -n ${${(As: :)line}[1]}
a

Pier Paolo Grassi
linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217
founder: https://www.meetup.com/it-IT/Machine-Learning-TO


Il giorno mer 22 apr 2020 alle ore 18:47 Mikael Magnusson <mikachu@xxxxxxxxx>
ha scritto:

> On 4/22/20, Pier Paolo Grassi <pierpaolog@xxxxxxxxx> wrote:
> > I am trying to use field splitting to get the first word of a line. I am
> > using:
> >
> > echo -n ${${(s: :)line}[1]}
> > when input contains spaces I get the first word as needed, eg:
> > line is: /usr/bin/python  - /usr/bin/python /usr/local/bin/terminator
> > what is printed:  /usr/bin/python
> >
> > when input does not contains spaces, however, all I get is the first
> > character of the line, eg:
> > line is: /usr/bin/zsh
> > what is printed: /
> >
> > I have trid forcing the array expansion in various ways:
> >   ${${(@s: :)line}[1]}
> >   ${${(s: :)line[@]}[1]}
> >   ${"${(s: :)line[@]}"[1]}
> >
> > but I  couldn't get the desidered behaviour
> > what am I missing?
>
> echo -n ${${(As: :)line}[1]}
>
> --
> Mikael Magnusson
>


Messages sorted by: Reverse Date, Date, Thread, Author