From: Pier Paolo Grassi <pierpaolog@gmail.com>
To: Zsh-Users List <zsh-users@zsh.org>
Subject: field splitting
Date: Wed, 22 Apr 2020 18:43:25 +0200 [thread overview]
Message-ID: <CAP+y1xB2m980w0s1N2SdLuf9ibdcLUUJgTaq1hEM0d6Eq9VXCA@mail.gmail.com> (raw)
[-- 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
next reply other threads:[~2020-04-22 16:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-22 16:43 Pier Paolo Grassi [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAP+y1xB2m980w0s1N2SdLuf9ibdcLUUJgTaq1hEM0d6Eq9VXCA@mail.gmail.com \
--to=pierpaolog@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).