怎么用最简短的代码写一个程序输出程序本身?

13次阅读

写一个程序输出自己本身的代码。最好是脚本语言。

周翔

#!/bin/cat
doewujdoweijdoweijdoweijdowejdoiwe

哈哈,自问自答。

周翔

整个shell的

#!/bin/bash
cat $0

再整个php的

<?php
$fileContents = file_get_contents(__FILE__);
echo $fileContents;

最后赠送个perl的

#!/usr/bin/perl
use FindBin qw($Bin);
open (LOGFILE, $Bin . "/" . $0);
$line = <LOGFILE>;
while(<LOGFILE>) {
    print $line;
    $line = <LOGFILE>;
}

gaosboy

<?php
#php天生的优势
highlight_file(__FILE__);

util

正文完