0
\$\begingroup\$

This question already has an answer here:

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\$

marked as duplicate by Mego, Blue, NoOneIsHere, Digital Trauma code-golf Aug 26 '16 at 17:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    \$\begingroup\$ Possibly dupe of the cheating quine challenge? Idk though. \$\endgroup\$ – Rohan Jhunjhunwala Aug 26 '16 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\$ – vikarjramun Aug 26 '16 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\$ – Mego Aug 26 '16 at 17:01
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.