[英]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.我正在创建一个 zsh 脚本,用于批量调整、转换和重命名 Web 开发的图像集。
The zsh function is structured like below: zsh 函数的结构如下:
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:我怎样才能从命令中传递一个参数,比如
img "something"
所以 zmv in-function 命令可以是:
zmv '(*).(*)' 'something$1.$2'
Thanks!谢谢!
This will prefix the second argument to zmv
with the first argument passed to img
:这将为
zmv
的第二个参数加上传递给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.这是有效的,因为第一个
$1
没有被引用,因此在传递给zmv
之前进行了评估,而'$1.$2'
是在单引号中,因此作为文字字符串传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.