最短的非空 bash quine

Shortest non-null bash quine

最短的bash quine是空串:

$ bash -c ''
$ 

生成自己的源代码作为输出的最短非空 bash 脚本是什么?

19个字符:

$echo 'echo $BASH_COMMAND' > quine
$ wc -c quine
19 quine
$ cat quine
echo $BASH_COMMAND
$ bash quine
echo $BASH_COMMAND
$

字符数包括源中的换行符(因为它是在输出中生成的)。


如果您之前没有听说过 $BASH_COMMANDthe manual 表示:

BASH_COMMAND

The command currently being executed or about to be executed, unless the shell is executing a command as the result of a trap, in which case it is the command executing at the time of the trap.

我觉得:

cat [=10=]

应该可以,但他们不接受

我想我只是偶然发现了一个 bash quine,它可能是最短的 non-empty 一个,虽然有点作弊:

你这样写一个文件:

#!/bin/cat

对文件chmod a+x执行

然后执行 ./file

输出将产生文件本身的内容 lol