0

I would like to make this command xrandr -s 640x480 use variables like so

#!/bin/bash

display_x=640
display_y=480

xrandr -s $display_xx$display_y

The command does not run correctly. How can I do this?

5
#!/bin/bash

display_x=640
display_y=480

xrandr -s ${display_x}x${display_y}
  • Oh, braces, I saw that somewhere online. Thank you sir. – xinthose Aug 8 '17 at 2:54
1

You should always put shell variables into quotes unless you have a good reason not to, and you’re sure you know what you’re doing.  So Deathgrip’s answer should be

xrandr -s "${display_x}x${display_y}"

and that is the way I would probably do it.  But

xrandr -s "$display_x"x"$display_y"

will also work.  Here’s another approach:

display_x=640
display_y=480
x=x
xrandr -s "$display_x$x$display_y"

— anything to tell the shell that you’re not trying to reference a variable named display_xx.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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