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

Re: Get the result of the last glob



2019-08-21 17:51:11 +0430, Aryn Starr:
> Is there a way to get the result of the last glob?
> I want to do sth like this in a folder with only one file, somebook.mobi:
> 
> ebook-convert * *.epub
> 
> Which I want expanded to:
> 
> ebook-convert somebook.mobi somebook.mobi.epub
[...]

You could use zargs for that:

autoload -Uz zargs # in ~/.zshrc

zargs -I@ ./* -- ebook-convert @ @.epub

Though I generally find that using a loop is generally quicker,
shorter and safer (and you have more control over what's going
on):

(for f (./*) ebook-convert $f $f.epub)

(using a subshell to get a more deterministic behaviour upon
^C/^Z).

Here, assuming that "ebook-convert" supports the --
end-of-option delimiter (if it doesn't replace -p with -P and *
with ./*), you could also do:

autoload -Uz zmv # in ~/.zshrc

zmv -p ebook-convert '*' '$f.epub'

Or 

alias wzmv='noglob zmv -W' # in ~/.zshrc

wzmv -p ebook-convert * *.epub

zmv does some sanity checks which you could find useful here,
like that none of the destination files exist before starting
the moves.

-- 
Stephant



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