Reading output into a script variable
Hi all,
I've been able to make progress on my own but I'm stuck. This is what I have in a bash script: Code:
res="$(xrandr -q|grep \"*\")" " 1600x1200 60.0*+" -- without the quotes but WITH the leading spaces. Of all the lines returned by xrandr -q, only one will have the asterisk in it (showing the current resolution). This is a laptop that will either be connected to an external monitor (1600x1200 resolution) or not (1400x1050 resolution). How can I evaluate the returned value in an "if" statement? What is the meaning of the :1:1 in the if statement above? Is this some sort of array index? Thanks in advance :) |
The backslashes seem to be the problem. You want to evaluate the first non-white text, so this works:
Code:
#!/bin/bash |
set -- $(xrandr -q|grep "*")
is enough, do not need that $(echo ...) about ${res:1:1} see man bash, parameter expansion, substring |
Thanks so much, both of you, and yes, the discussion on parameter expansion and substring is very useful.
Here's what I ended up with: in /etc/lightdm/lightdm.conf.d I have a file simply named "my.conf" which has the following: Code:
[SeatDefaults] One directory up from than, in /etc/lightdm, I have the script named lightdmxrandr.sh: Code:
#!/bin/sh Tested, works beautifully. if you see anything in my bash code that is wrong, I'd appreciate the feedback (I'm more of an OO programmer -- java, PowerBuilder -- and SQL programmer, I have a lot to learn about bash scripting). Either way, thanks so much both of you! :) |
All times are GMT -5. The time now is 12:16 AM. |