0

I am running Antergos linux with Gnome 3.18.2 on a Dell XPS 12 Convertible laptop/tablet, and am working on making the screen rotation more convenient.

I pulled a version of the following script from an Ubuntu forums post and modified it to match my display name, etc. Each line has the expected result when run on its own, but when I run the actual script, nothing happens - no errors, no screen rotation, nothing:

 #!/bin/sh
rotation='xrandr -q --verbose|grep eDP1|cut -b45-50'
if [[ $rotation = "normal" ]] ;
then
  xrandr -o right
else
  xrandr -o normal
fi

Any ideas why this is not working as expected?

Thanks in advance!

  • 3
    Seems like you are trying to set rotation via command substitution, but with wrong syntax. Try rotation=$(xrandr -q ...). Right now you just set your rotation var as the string containing your plain command, hence the test has to fail and your screen stays the same. – pidi Mar 8 '16 at 22:02
  • 1
    Thanks Pidi, that did it! If you want to post this as an answer rather than a comment, I will mark it as the correct answer. – mblasco Mar 8 '16 at 23:11
1

Quick Solution


The way you set rotation results in your variable containing the written-out command you wanted to take the output from.
What you want to do is using command substitution to store the output of your command in rotation. You can achieve this by using rotation=$(xrandr -q ...) or rotation=`xrandr -q ...`.

Background


Command substitution executes your command in a subshell and stores its output written to stdout in your variable. It's a common thing to do, and I personally prefer using $().

You can read more on command substitution on the Bash Hackers Wiki.

By using single-quotes (strong quoting) you tell bash to not expand anything within the quotes. For example, with a='$FOO', $a stays $FOO. Bash leaves the stuff you quoted untouched and directly shuffles it into your variable.

More on quoting can also be found on the Bash Hackers Wiki.

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.