理解这个shell语句

War*_*ith 8 command-line special-characters

我承认这是一项家庭作业,但我无法解释以下命令行:

警告:这是所谓的叉形炸弹!这个命令行会消耗所有 RAM 和 CPU 使你的电脑崩溃(相信我,我试过了......)

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

据我所知,我应该在这里独自完成到目前为止我所拥有的(搜索这些字符非常令人沮丧)。

  1. 管道可以将一些命令连接在一起,以便第一个输出被第二个用作输入。
  2. & 是在后台运行命令(基本上用于从不应被命令阻止的 shell 启动某些内容)

我猜:是fork?但在这里我完全迷路了!我愿意学习,所以也许有人有很好的资源可以让我阅读?

Egi*_*gil 14

:()      # 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)

资料来源:维基百科上的叉形炸弹

  • 好的,所以你是一个邪恶的坏黑客 :) 无论如何谢谢!帮了我很多 (2认同)