r*********r 发帖数: 3195 | 1 sys admin... 经常一点点小事搞不定。
很多时候实在难以忍受了,索性自己搞定。
但有时候一些 工具shell script 是 sys admin 写的,
拿来一看,一下子还看不懂。。。
细细琢磨一下,又发现逻辑其实很简单,
难懂的无非就是一些特殊符号,一条命令的某个不常见的选项,etc.
但是等弄完,一天差不多就过去了,什么都没干成。。。 ORZ, 真是要撞墙。 | r*********r 发帖数: 3195 | 2 今天一大早又来琢磨一个 shell script,
发现写 shell 的人一般过于依赖 pipe,
经常是一大串命令用管道串起来,
这种东西真的很脆弱啊,只要其中一个命令 got stuck,
后面的就完全动不了了,也没有报错信息。。。 | A**u 发帖数: 2458 | | r****c 发帖数: 1494 | 4 http://www.faqs.org/docs/artu/ten-thousand.html
Master Foo and the Ten Thousand Lines
Master Foo once said to a visiting programmer: “There is more Unix-nature
in one line of shell script than there is in ten thousand lines of C.”
The programmer, who was very proud of his mastery of C, said: “How can this
be? C is the language in which the very kernel of Unix is implemented!”
Master Foo replied: “That is so. Nevertheless, there is more Unix-nature in
one line of shell script than there is in ten thousand lines of C.”
The programmer grew distressed. “But through the C language we experience
the enlightenment of the Patriarch Ritchie! We become as one with the
operating system and the machine, reaping matchless performance!”
Master Foo replied: “All that you say is true. But there is still more Unix
-nature in one line of shell script than there is in ten thousand lines of C
.”
The programmer scoffed at Master Foo and rose to depart. But Master Foo
nodded to his student Nubi, who wrote a line of shell script on a nearby
whiteboard, and said: “Master programmer, consider this pipeline.
Implemented in pure C, would it not span ten thousand lines?”
The programmer muttered through his beard, contemplating what Nubi had
written. Finally he agreed that it was so.
“And how many hours would you require to implement and debug that C program
?” asked Nubi.
“Many,” admitted the visiting programmer. “But only a fool would spend
the time to do that when so many more worthy tasks await him.”
“And who better understands the Unix-nature?” Master Foo asked. “Is it he
who writes the ten thousand lines, or he who, perceiving the emptiness of
the task, gains merit by not coding?”
Upon hearing this, the programmer was enlightened. | r*********r 发帖数: 3195 | 5 raymond 的小故事? 骗骗小孩的。
我觉得shell致命的弱点是把 command 当成 function 来用。
但是 command 出错的机率比一般的 function 高了几个量级,
shell 又没有很好的查错机制 (profiling, debugging,
checking return value, catching exceptions, etc)。
所以大部分的 shell script 比较脆弱。
上次的事,后来还是我自己找到了 stuck 的 command,
又单独 strace 了一下那个命令,才解决问题。
一般不怎么编程的 sys admin,还是不给力。跟编程的人比起来差远了。
【在 r****c 的大作中提到】 : http://www.faqs.org/docs/artu/ten-thousand.html : Master Foo and the Ten Thousand Lines : Master Foo once said to a visiting programmer: “There is more Unix-nature : in one line of shell script than there is in ten thousand lines of C.” : The programmer, who was very proud of his mastery of C, said: “How can this : be? C is the language in which the very kernel of Unix is implemented!” : Master Foo replied: “That is so. Nevertheless, there is more Unix-nature in : one line of shell script than there is in ten thousand lines of C.” : The programmer grew distressed. “But through the C language we experience : the enlightenment of the Patriarch Ritchie! We become as one with the
| r*********r 发帖数: 3195 | 6 the visiting programmer 有找master foo 这闲工夫,
不如把 unix command 的源程序都看一遍。
像什么 find, xargs, sort之类的,解释起来很费劲。
很多书费了半天劲,举了若干垃圾例子,还是讲不清楚。
源代码看一下其实很简单。 | r*********r 发帖数: 3195 | 7 顺便吐糟一下,关于 shell programming, command line 的书出了不少,
大部分都是垃圾书啊。能看得下去的太少了。 |
|