2

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?

2 Answers 2

6
#!/bin/bash

display_x=640
display_y=480

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

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.