Skip to content
Advertisement

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

Environment

System: Linux Mint 18 / 19 Cinnamon 64-bit.

Shell: dash (POSIX).


Question

I need to dynamically account for the screen resolution in a POSIX shell script.

I prefer a function for re-use.

Advertisement

Answer

Function

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

Usage

resolution=$(get_screen_resolution)
Advertisement