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

Re: Applying glob qualifiers to non-variable types



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



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