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

field splitting



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?

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


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