1
\$\begingroup\$

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.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Possibly dupe of the cheating quine challenge? Idk though. \$\endgroup\$ Aug 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\$ Aug 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\$
    – user45941
    Aug 26, 2016 at 17:01

3 Answers 3

5
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

Bash, 7

echo $0

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

\$\endgroup\$
1
\$\begingroup\$

C, 23 bytes

main(){puts(__FILE__);}

Try it on Ideone

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.