0

On Lubuntu 16.02, this command shows information about all desktops:

$ wmctrl -d
0  - DG: 3926x1600  VP: 0,0  WA: 0,24 2560x1576  desktop 1
1  - DG: 3926x1600  VP: 0,0  WA: 0,24 2560x1576  desktop 2
2  * DG: 3926x1600  VP: 0,0  WA: 0,24 2560x1576  desktop 3
3  - DG: 3926x1600  VP: 0,0  WA: 0,24 2560x1576  desktop 4
4  - DG: 3926x1600  VP: 0,0  WA: 0,24 2560x1576  desktop 5

Need to store and process the information about the active desktop, what shows up by:

$ wmctrl -d | grep "*"
2  * DG: 3926x1600  VP: 0,0  WA: 0,24 2560x1576  desktop 3

For some strange reason, this solution won't store the information needed:

$ activedesktop=$(wmctrl -d | grep "*")
$ echo $activedesktop
2 Desktop Documents Downloads Mail Music Pictures Public Videos DG: 3926x1600 VP: 0,0 WA: 0,24 2560x1576 desktop 3

As the variable inserts the home directories names where the "*" was supposed to be.

Why is this happening, and how to solve it?

melpomene
  • 84,125
  • 8
  • 85
  • 148
nightcod3r
  • 752
  • 1
  • 7
  • 26

1 Answers1

1

As pointed out by @melpomene, the variable does store the information needed, but the former echo interprets the asterisk.

So, the solution is just to double-quote the variable as in echo "$activedesktop".

nightcod3r
  • 752
  • 1
  • 7
  • 26