I was going to post this on your follow up question which has been flagged as duplicate. You asked in that question what this script was doing. This entire script can be broken down like:
- We are setting the variable
ids
to the following
- Take the output from
xinput --list
and pipe it to awk
- Before starting the awk script set awk variable
search
to shell variable $SEARCH
. So a $SEARCH
needs to be set first. -v search="$SEARCH"
- Processing each record, test to see if anywhere in the entire record (
$0
) the value stored in variable search
is found. If so, proceed.
- Using
match()
test the entire record ($0
) again, but this time with regex string id=[0-9]+
which would be a string containing id=
followed by 1 or more numbers. Match will set awk variable RSTART
with the starting position of the match.
- if RSTART is set, then a match was found, so...
- Print the substring of the entire record (
$0
) starting three characters after match was found (in this case after id=
) for the length of the match RLENGTH
minus 3 characters. Essentially whatever numbers are found after the id
.
So stating this in english. Set variable $SEARCH to something that you are searching for in the output of xinput --list
. This awk script will find the line that matches that search string. It will look for an id=<some numbers>
on the same line of the xinput --list
output and return those numbers.
An example:
If xinput --list
spits out the following two lines:
This is the first line of xinput --line and the id=12345
This is the second line of xinput --line and the id=67891
If you set SEARCH="second"
and then executed this statement it would output 67891
and store it in variable ids
.