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

Re: field splitting



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