#!/bin/sh /etc/rc.comon
OpenWRT中的procd脚本中使用了#!/bin/sh /etc/rc.comon这样的语句,总结了一下它的一些机制。
http://www.cnblogs.com/merlindu/p/6475305.html
merlin@mdoa10 ~ $ head -n 13 etc/init.d/network(列出脚本前面的一部分)
1 #!/bin/sh /etc/rc.common 2 3 START=10 4 STOP=90 5 6 USE_PROCD=1 7 8 init_switch() { 9 setup_switch() { return 0; } 10 11 include /lib/network 12 setup_switch 13 }
该脚本(etc/init.d/network)中第1行 #!/bin/sh /etc/rc.common其实是将整个shell的控制权交到了 /etc/rc.comon这个脚本,从第2行开始的所有shell语句只能被动地被rc.common中的语句所调用。
并且,对于rc.common这个脚本而言:
${0}的值为/etc/rc.common,即这个脚本本身;
${1}的值为network(假设工作目录为/etc/init.d/,若使用绝对调用,如执行/etc/init.d/network restart则${1}的值变为/etc/init.d/network,其他情况依此类推);
${2}为/etc/init.d/network脚本的第1个参数,如执行/etc/init.d/network restart则为restart;
${3}及后面的都遵循${2}的规则。
如需要运行上面从第2行开始的语句,应该在/etc/rc.common脚本中显式调用,即 . ${1} (在/etc/rc.common中使用source ${1}似乎要报错,原因目前未知),但/etc/init.d/network脚本不再能够获取${1}、${2}、${3}这些变量了(${0}仍然可以)。