我正在尝试将我的照片分类为纵向和横向。我想出了一个命令来打印 jpeg 的大小尺寸:
identify -format '%w %h\n' 1234.jpg
1067 1600
如果我在 bash 脚本中使用它来将所有风景图片移动到另一个文件夹,我希望它类似于
#!/bin/bash
# loop through file (this is psuedo code!!)
for f in ~/pictures/
do
# Get the dimensions (this is the bit I have an issue with)
identify -format '%w %h\n' $f | awk # how do I get the width and height?
if $width > $hieght
mv ~/pictures/$f ~/pictures/landscape/$f
fi
done
一直在查看 awk 手册页,但我似乎找不到语法。
最佳答案
您可以使用数组
:
# WxH is a array which contains (W, H)
WxH=($(identify -format '%w %h\n' $f))
width=${WxH[0]}
height=${WxH[1]}
关于string - Bash 将输出解析为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10187617/