I am a JavaScript/Java programmer having difficulty with writing a bash script. Below Is the output I am to be dealing with:
karl@karl-laptop:~/.scripts/startup$ xinput list
⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ Logitech USB Receiver                     id=10   [slave  pointer  (2)]
⎜   ↳ Logitech USB Receiver                     id=11   [slave  pointer  (2)]
⎜   ↳ PS/2 Logitech Wheel Mouse                 id=15   [slave  pointer  (2)]
⎜   ↳ SteelSeries Sensei Raw Gaming Mouse       id=16   [slave  pointer  (2)]
⎜   ↳ SteelSeries Sensei Raw Gaming Mouse       id=17   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Video Bus                                 id=8    [slave  keyboard (3)]
    ↳ Sleep Button                              id=9    [slave  keyboard (3)]
    ↳ USB2.0 UVC HD Webcam                      id=12   [slave  keyboard (3)]
    ↳ Asus WMI hotkeys                          id=13   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=14   [slave  keyboard (3)]
    ↳ SteelSeries Sensei Raw Gaming Mouse       id=18   [slave  keyboard (3)]
I wish to acquire the id's of both the Virtual core pointer SteelSeries Sensei Raw Gaming Mouse. This means I wish to end up with the id's:
16
17
Preferably in their own variables as I will be editing the settings of both in different ways. I currently have the following script but it doesn't do anything:
#!/bin/bash
ids=$(xinput list | awk 'SteelSeries Sensei Raw Gaming Mouse')
echo $ids[0]
echo $ids[1]
unset $ids
I tried to use the following script in this question but it didn't work, it just echo'd all of the id's: How to make a program that finds id's of xinput devices and sets xinput some settings
I did modify it so that it collected all of the id's that matched SteelSeries Sensei Raw Gaming Mouse:
ids=$(xinput --list | awk -v search='SteelSeries Sensei Raw Gaming Mouse' \
    '$0 ~ search {match($0, /id=[0-9]+/);\
                  if (RSTART) \
                    print substr($0, RSTART+3, RLENGTH-3)\
                 }'\
     )
for i in $ids
do
    echo $i
done
echo $ids[0]
echo $ids[1]
Output:
16
17
18 // <-- wrong! should not be there
16 17 18[0] // <-- I only wanted the number '16' here
16 17 18[1] // <-- I only wanted the number '17' here
However it also collected the Virtual core keyboard which I do want (number 18 as you can see)