From: Pier Paolo Grassi <pierpaolog@gmail.com>
To: Mikael Magnusson <mikachu@gmail.com>
Cc: Zsh-Users List <zsh-users@zsh.org>
Subject: Re: field splitting
Date: Wed, 22 Apr 2020 19:11:38 +0200 [thread overview]
Message-ID: <CAP+y1xDGKs45QE6fjxgrfentSfpxR+ZMfqPff=mtFp-atqT3bw@mail.gmail.com> (raw)
In-Reply-To: <CAHYJk3SBrkdRHWSm=UM=de9+jSHCgpiGE-Q+0xf6OE3P0xQA5A@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1110 bytes --]
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@gmail.com>
ha scritto:
> On 4/22/20, Pier Paolo Grassi <pierpaolog@gmail.com> 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
>
next prev parent reply other threads:[~2020-04-22 17:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-22 16:43 Pier Paolo Grassi
2020-04-22 16:47 ` Mikael Magnusson
2020-04-22 17:11 ` Pier Paolo Grassi [this message]
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+y1xDGKs45QE6fjxgrfentSfpxR+ZMfqPff=mtFp-atqT3bw@mail.gmail.com' \
--to=pierpaolog@gmail.com \
--cc=mikachu@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).