hamza
Posts: 76
Joined: Fri Apr 03, 2015 7:16 pm

read screen

Fri May 08, 2015 12:15 pm

hi
how can read screen dimensions as two variables(wxh)??
because the below command read it as a line wxh
xdpyinfo | grep 'dimensions:'

also where can I find complete reference for bash script with examples??

User avatar
DougieLawson
Posts: 38883
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: read screen

Fri May 08, 2015 12:40 pm

Code: Select all

#!/bin/bash
SIZES=$(awk '/fbwidth/{ print $2 " " $3}' /proc/cmdline)
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
B.Goode
Posts: 10191
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: read screen

Fri May 08, 2015 1:01 pm

hamza wrote:where can I find complete reference for bash script with examples??
man bash is comprehensive.

Or read the 'shell scripting' chapter in almost any book on using or administering a linux or unix system.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: read screen

Fri May 08, 2015 1:07 pm

B.Goode wrote: man bash is comprehensive.
The problem is that, like "man gcc" or reading the C standards documents, reading it won't really tell you how to program in it. That comes only with experience.

Incidentally, in answer to the original question, this works for me:

Code: Select all

pi@raspberrypi ~ $ set -- \
$(xdpyinfo | gawk '/dimensions/ {sub(/x/," ",$2);print $2}')
pi@raspberrypi ~ $ echo $1 $2
1280 778
pi@raspberrypi ~ $ 
Note: I reformatted the above so that the line wouldn't break on the main line. The point is that you convert the "x" into a single space. That wasn't made clear in the original rendering.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Return to “Beginners”