Output source file name

0

Write a program that prints the name of its source file. REPL environments are not allowed for this challenge. Your code must work in any file that your language's interpreter will accept. Your answer must also be a full program, not just a function. The source code's file extension must be printed. Leading or trailing newline are both optional. This is a code golf, so shortest answer wins. The winner will be chosen on September 2nd, 2016.

vikarjramun

Posted 2016-08-26T16:36:32.493

Reputation: 794

Question was closed 2016-08-26T17:03:14.180

1Possibly dupe of the cheating quine challenge? Idk though. – Rohan Jhunjhunwala – 2016-08-26T16:39:27.340

@Mego that question asks to actually reverse the charge filename in the file system. This is just printing the file name. So not a duplicate – vikarjramun – 2016-08-26T17:01:09.153

1@vikarjramun Reading the file name is a significant part of the challenge. This is a trivial subset of that challenge. – Mego – 2016-08-26T17:01:57.757

Answers

5

V, 3 bytes

"zp

Try it online!

This actually does work in the online interpreter somehow. ¯\_(ツ)_/¯

Explanation:

The 'z' register is predefined to the source file of the program, and p pastes from whatever register you tell it to. P would also work, and not cause any different output.

James

Posted 2016-08-26T16:36:32.493

Reputation: 54 537

2

Bash, 7

echo $0

So trivial, I have to type in this text to make the answer long enough.

Digital Trauma

Posted 2016-08-26T16:36:32.493

Reputation: 64 644

1

C, 23 bytes

main(){puts(__FILE__);}

Try it on Ideone

betseg

Posted 2016-08-26T16:36:32.493

Reputation: 8 493