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

Bash 这段代码在做什么(){::&;};:,bash,Bash,很抱歉问了这么一个一般性的问题,但这已经困扰了我好几天了 一位朋友给了我这段代码(?),但他不会告诉我它是做什么的,甚至不会告诉我它是C、bash还是其他任何东西 从外观上看,我觉得它像C。虽然我不明白为什么两边有: :(){:|:&};: 任何线索都将不胜感激。这是bash shell脚本,不是C 这是一个好主意 维基百科对此进行了解释: :() # define ':' -- whenever we say ':', do this: { # beginni

很抱歉问了这么一个一般性的问题,但这已经困扰了我好几天了

一位朋友给了我这段代码(?),但他不会告诉我它是做什么的,甚至不会告诉我它是C、bash还是其他任何东西

从外观上看,我觉得它像C。虽然我不明白为什么两边有

:(){:|:&};:

任何线索都将不胜感激。

这是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.

这是一个叉形炸弹,我不会在你的系统上运行它。这将导致大量进程生成,并最终减慢或崩溃您的系统。

我通常建议您“试试看”,但不要在这一个上。关键是要知道“:”符号是命令名。如果将其替换为外观更普通的变量名,则更容易发现:foo(){foo | foo&};foo诀窍在于,你的大脑将:视为另一个特殊角色。胡说!只要确保当您尝试从不受信任的源中执行“随机”代码时,您可以在非网络虚拟机中运行该代码。:)这不是一个朋友,我会从他那里得到更多的代码。。。如果他告诉你去做
chmod-R 666/
,我不会那么做,当然我没有运行它。fork在这里爆炸的唯一一件事是我的大脑=)这是bash中的一个语法错误。不过,它可能在zsh中运行。