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.
-
1\$\begingroup\$ Possibly dupe of the cheating quine challenge? Idk though. \$\endgroup\$– Rohan JhunjhunwalaAug 26, 2016 at 16:39
-
\$\begingroup\$ @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 \$\endgroup\$– vikarjramunAug 26, 2016 at 17:01
-
1\$\begingroup\$ @vikarjramun Reading the file name is a significant part of the challenge. This is a trivial subset of that challenge. \$\endgroup\$– user45941Aug 26, 2016 at 17:01
3 Answers
V, 3 bytes
"zp
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.
Bash, 7
echo $0
So trivial, I have to type in this text to make the answer long enough.