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.

1
  • 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. Commented Nov 5, 2018 at 15:06

1 Answer 1

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]}')

Not the answer you're looking for? Browse other questions tagged or ask your own question.