这段代码在做什么?:(){:|:&} ;:

Dim*_*mme 10 bash

很抱歉提出这样一个普遍的问题,但这已经困扰了我好几天.

一位朋友给了我这段代码(?)并且不会告诉我它的作用,或者即使它是C或bash或其他任何东西.

从它的外观来看,它看起来像C给我.虽然我不明白为什么有:这方面.

:(){:|:&};:
Run Code Online (Sandbox Code Playgroud)

任何线索将不胜感激.

SLa*_*aks 25

这是bash shell脚本,而不是C.

这是一个叉炸弹.

维基百科解释说:

:()      # define ':' -- whenever we say ':', do this:
{        # beginning of what to do when we say ':'
    :    # load another copy of the ':' function into memory...
    |    # ...and pipe its output to...
    :    # ...another copy of ':' function, which has to be loaded into memory
         # (therefore, ':|:' simply gets two copies of ':' loaded whenever ':' is called)
    &    # disown the functions -- if the first ':' is killed,
         #     all of the functions that it has started should NOT be auto-killed
}        # end of what to do when we say ':'
;        # Having defined ':', we should now...
:        # ...call ':', initiating a chain-reaction: each ':' will start two more.
Run Code Online (Sandbox Code Playgroud)

  • @SethCarnegie:**永远不要**运行不受信任的代码. (7认同)
  • 我通常建议"尝试看看",但不要推荐这个. (6认同)
  • 关键是知道':'符号是命令名称.如果你用一个更正常的变量名来替换它,那么更容易发现:foo(){foo | foo&}; foo诀窍是你的大脑看到:只是另一个特殊的角色. (3认同)