mknod error while trying to make a device driver file with shell

4.7k Views Asked by At

My code

#!/bin/sh
major=$(awk '$2=="module_dev" {print $1}' /proc/devices)
echo $major
mknod /dev/module_dev c $major 0

I'm practicing character device drivers, and this is one of the examples. The code above is ought to create a device driver file at /dev/ but there's an error that says

mknod: missing operand after '0'(it could be wrong because it's just a translation)
for more information type 'mknod --help'

This message was shown when I tried to create a device driver file (sh ***.h) I have no idea what the problem is. (insmod is already done)

1

There are 1 best solutions below

0
On

The most likely cause of this error is that $major has no value. That is, $major is blank.

You have the echo statement there: what does it show? If you don't see anything, you might want to enhance it to show nothing enlightenlingly;

echo "major='$major'"

which will produce something like

major='213'

if all is well, and show empty quotes if it is working like I suspect.