I’ve started studying “Linux Device Drivers 3rd ed” and i am having trouble understanding the syntax of the following script. I know basic shell scripting and can use the awk utility for making basic programs
Q1)/sbin/insmod ./$module.ko $* || exit 1
a)what was the need for stating the full path of insmod?
b)i’ve use ./ for invoking executable files but never seen ./ in the middle of a command.
c)is $module=scull???
d)what does $* mean?
e)what the double bat for ?
Q2)major=$(awk “\$2= =\”$module\” {print \$1}” /proc/devices)
What are the steps this awk statement goes through to get us the scull devices?
i dont get the double slashes ‘\’ and the double equal sign.
#!/bin/sh
module="scull"
device="scull"
mode="664"
# invoke insmod with all arguments we got
# and use a pathname, as newer modutils don't look in . by default
/sbin/insmod ./$module.ko $* || exit 1
# remove stale nodes
rm -f /dev/${device}[0-3]
major=$(awk "\\$2= =\"$module\" {print \\$1}" /proc/devices)
mknod /dev/${device}0 c $major 0
mknod /dev/${device}1 c $major 1
mknod /dev/${device}2 c $major 2
mknod /dev/${device}3 c $major 3
Q1
a) The need to state the full path for insmod because it will always accessible even though you are in location that is not defined in PATH
b) ./something means something is a file located in current path. ./$module.ko means that file ./scull.ko
c) same as b
d) $* means whatever parameters that you give to the shell script.
e) double pipe (or bat) means OR. It means, insmod the module, or if fail, exit with return value 1
I dont have answer for Q2. Sorry.