简体   繁体   中英

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:

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

Thanks!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM