Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to pass customized zsh function argument to in-block zmv commands?

I am creating a zsh script that batch resize, convert and rename set of images for web dev.

The zsh function is structured like below:

function img() {
    # lines of "magick -resize" and "magick mogrify -format"

    autoload zmv
    zmv '(*).(*)' '$1.$2'
}

How can i pass an argument from the command like img "something" so the zmv in-function command can be:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

zmv '(*).(*)' 'something$1.$2'

Thanks!

>Solution :

This will prefix the second argument to zmv with the first argument passed to img:

img() {
  zmv '(*).(*)' $1'$1.$2'
}

This works because the first $1 is unquoted and thus evaluated before it is passed to zmv, whereas '$1.$2' is in single quotes and thus passed as a literal string.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading