0

I am trying to read raspberry pi resolution using the tvservice command into two variables: X & Y.

When running:

tvservice --status | awk '{print $9}'

I am getting:

1920x1800 

Which is exactly what I am looking for.

What I am trying to figure out, is how to split them into two bash variables where X=1920 and Y=1800 so I can use them later on in my script.

Micha Wiedenmann
  • 18,825
  • 20
  • 87
  • 132
badatz
  • 53
  • 7
  • Most of the context is not really necessary as you seem to be asking: Given the string `1920x1800` how can I split it into `X` and `Y`. – Micha Wiedenmann Nov 05 '18 at 15:06

1 Answers1

0

Could you please try following. Where simply we create 2 variables named X and Y and in spite of printing the $9 we are splitting it with using split function of awk and then printing their 1st element for variable X and 2nd element for 2nd element.

X=$(tvservice --status | awk '{split($9,array,"x");print array[1]}')
Y=$(tvservice --status | awk '{split($9,array,"x");print array[2]}')
RavinderSingh13
  • 117,272
  • 11
  • 49
  • 86