pid=`cat $pidfile` or read pid <$pidfile?

后端 未结 2 1606
不思量自难忘°
不思量自难忘° 2021-02-20 10:38

I read a lot of init.d scripts and:

pid=`cat $pidfile`

lines make me sad. I don\'t understand why people doesn\'t use:

<         


        
2条回答
  •  广开言路
    2021-02-20 11:11

    The read pid < file way is the Best Practice for the reason you stated: much cheaper than a fork/exec of cat.

    As for why so many scripts do this the expensive way, I can only speculate. Probably cut'n'paste from other people's scripts, together with lack of knowledge of shell features, together with blazingly fast CPUs. Who reads man pages when there's Stack Overflow? :-) Especially the shell man page is a hard-to-read reference manual for novices due to all the terminology introduced.

    Who said Useless Use of Cat was a privilege for pipes?

提交回复
热议问题