Meaning of this shell script line with awk

A better way to write this would be :

major=$(awk -v mod=$module '$2==mod{print $1}' /proc/devices)

I read this too but that line was not working for me. I had to modify it to

major=$(awk "\$2 == \"$module\" {print \$1}" /proc/devices)

The first part \$2 == \"$module\" is the pattern. When this is satisfied, that is, the second column is equal to "scull", the command print \$1 is executed which prints the first column. This value is stored in the variable major. The $ needs to be escaped as they need to be passed as it is to awk.

Tags:

Shell

Bash

Awk