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:
<
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?