zsh-users
 help / color / mirror / code / Atom feed
* field splitting
@ 2020-04-22 16:43 Pier Paolo Grassi
  2020-04-22 16:47 ` Mikael Magnusson
  0 siblings, 1 reply; 11+ messages in thread
From: Pier Paolo Grassi @ 2020-04-22 16:43 UTC (permalink / raw)
  To: Zsh-Users List

[-- Attachment #1: Type: text/plain, Size: 753 bytes --]

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-04-22 18:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-22 16:43 field splitting Pier Paolo Grassi
2020-04-22 16:47 ` Mikael Magnusson
2020-04-22 17:11   ` Pier Paolo Grassi
2020-04-22 17:18     ` Roman Perepelitsa
2020-04-22 17:46       ` Pier Paolo Grassi
2020-04-22 17:51         ` Roman Perepelitsa
2020-04-22 17:53           ` Pier Paolo Grassi
2020-04-22 18:04             ` Roman Perepelitsa
2020-04-22 18:18               ` Pier Paolo Grassi
2020-04-22 18:14             ` Bart Schaefer
2020-04-22 18:20               ` Pier Paolo Grassi

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).