3

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)

P̲̳x͓L̳
  • 3,615
  • 3
  • 29
  • 37
user3062950
  • 61
  • 1
  • 6
  • then what could be the problem? major is specified and minor is 0 – user3062950 Mar 22 '14 at 03:55
  • Always quote your shell variables unless you have a very specific reason not to and fully understand all of the implications. Change `$major` to `"$major"` throughout your script then run it again and tell us if there's still a problem. That may not solve your problem, but until you're quoting your variables there's no point looking at it. – Ed Morton Mar 22 '14 at 14:28
  • What is the output of the `echo $major`? – CL. Mar 23 '14 at 14:28
  • Add `set -x` after `#!/bin/sh`. My guess is that `$major` is not filled properly. – Ortwin Angermeier Mar 23 '14 at 21:33
  • The error occurred because I left the device driver number after the first trial of mknod. I solved it by clearing the device information at /proc/devices and /dev. Anyway thanks for helping all. – user3062950 Apr 10 '14 at 13:59

1 Answers1

0

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.

wallyk
  • 56,922
  • 16
  • 83
  • 148