zsh-users
 help / color / mirror / code / Atom feed
* Applying glob qualifiers to non-variable types
@ 2012-11-16 18:00 Matthias Vallentin
  2012-11-16 19:55 ` Oliver Kiddle
  0 siblings, 1 reply; 3+ messages in thread
From: Matthias Vallentin @ 2012-11-16 18:00 UTC (permalink / raw)
  To: zsh-users

I have a scenario where a command gives similar output to find, .e.g.,

    ./path/to/foo.ext
    ./path/to/bar.ext

I was wondering if it is possible to use glob qualifier to handle the
output in the following way:

    command | print <?>:t:r

where <?> would be some magic I am missing. I tried to capture STDIN in
various ways $(</dev/stdin), $(<&0), etc., but could not find working
solution.

   Matthias


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

* Re: Applying glob qualifiers to non-variable types
  2012-11-16 18:00 Applying glob qualifiers to non-variable types Matthias Vallentin
@ 2012-11-16 19:55 ` Oliver Kiddle
  2012-11-16 21:55   ` Valodim Skywalker
  0 siblings, 1 reply; 3+ messages in thread
From: Oliver Kiddle @ 2012-11-16 19:55 UTC (permalink / raw)
  To: Matthias Vallentin; +Cc: zsh-users

Matthias Vallentin wrote:
> I have a scenario where a command gives similar output to find, .e.g.,
> 
>     ./path/to/foo.ext
>     ./path/to/bar.ext
> 
> I was wondering if it is possible to use glob qualifier to handle the
> output in the following way:
> 
>     command | print <?>:t:r
> 
> where <?> would be some magic I am missing. I tried to capture STDIN in
> various ways $(</dev/stdin), $(<&0), etc., but could not find working
> solution.

You can use a while loop - something like:
  command | while read file; do
    print $file:t:r                     
  done

If you're using a command that, unlike print, can't be invoked for each
file separately then you can use something like the following:

  print ${^$(command)}(:t:r)

The caret is only needed if you don't set rcexpandparam.

To cope with files with spaces in their names you need to use something
like ${(f)^"$(command)"}(:t:r)

Oliver


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

* Re: Applying glob qualifiers to non-variable types
  2012-11-16 19:55 ` Oliver Kiddle
@ 2012-11-16 21:55   ` Valodim Skywalker
  0 siblings, 0 replies; 3+ messages in thread
From: Valodim Skywalker @ 2012-11-16 21:55 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Matthias Vallentin, zsh-users

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

You can actually apply these kinds of operations to arrays, ie:

# read into array, linewise
files=( ${(f)"$(command)"} )

# use :t and :r on array - those apply per element
print -l ${files:t:r}

 - V

[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]

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

end of thread, other threads:[~2012-11-16 22:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-16 18:00 Applying glob qualifiers to non-variable types Matthias Vallentin
2012-11-16 19:55 ` Oliver Kiddle
2012-11-16 21:55   ` Valodim Skywalker

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).