string - Bash 将输出解析为变量

标签 string bash awk jpeg

我正在尝试将我的照片分类为纵向和横向。我想出了一个命令来打印 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/

相关文章:

C++在shell中使用计时器执行多个命令

linux - 在 bash 中交换列

python - 根据列名创建 DataFrame 的子集

sql - 计算字符串开头和结尾处的空格(ASCII 代码 32)

bash - 在 shell/bash 脚本中的文件之间使用变量

bash - 如何使用 cURL 在 shell 中遍历远程文件的行?

linux - 使用 awk 清理 csv 文件的标题

linux - 将文本文件中的部分文件名与目录中的文件名进行比较(grep + awk)

java - 从字符串数组中获取特定项目

c++ - 为什么在 c++ 中使用 c 字符串?