如何在 Linux 上的 shell 脚本中获取屏幕分辨率

How do I get screen resolution in a shell script on Linux

环境

系统:LinuxMint 18 / 19 Cinnamon 64 位。

Shell: dash (POSIX).


问题

我需要在 POSIX shell 脚本中动态考虑屏幕分辨率。

我更喜欢重复使用的功能。

函数

get_screen_resolution()
{
    xdpyinfo | awk '/dimensions:/ { print  }'
}

用法

resolution=$(get_screen_resolution)