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/shrotation='xrandr -q --verbose|grep eDP1|cut -b45-50'if [[ $rotation = normal ]] ;then  xrandr -o rightelse  xrandr -o normalfiAny ideas why this is not working as expected?Thanks in advance!
Trouble with Screen Rotation Script
shell script;xrandr;antergos
Quick SolutionThe 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 ...`.BackgroundCommand 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.