[Question]
  [
Long-time lurker, first-time poster. So here goes.
In the Wikipedia page for [quine](https://en.wikipedia.org/wiki/Quine_%28computing%29#.22Cheating.22_quines), it says that "a quine is considered to be 'cheating' if it looks at its own source code." Your task is to make one of these "cheating quines" that reads its own source code.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes - *in each language* - wins. This means that a 5-byte Pyth script would not beat a 21-byte Python script - but a 15-byte Python script would.
You must use file I/O to read the source code, so the following JavaScript code, taken from the official Wikipedia page, is invalid:
```
function a() {
    document.write(a, "a()");
}
a()
```
It must access the source code of the file *on disk*.
**You are not allowed to specify the file name. You must make it detect the filename itself.**
Everyone clear? Go!
  
[Answer]
# [Zsh](https://www.zsh.org/), 4 bytes
```
<$0
```
The Z shell has feline functionalities built in. The fourth character is a linefeed.
[Try it online!](https://tio.run/nexus/zsh#@2@jYsD1/z8A "Zsh ‚Äì TIO Nexus")
The code does not depend in any way on the file name; it works even if the file name contains special character, such as spaces or newlines.
### Test run
```
$ cat "my quine.sh"
<$0
$ zsh "my quine.sh" 
<$0
$ diff -s <(zsh "my quine.sh") <(cat "my quine.sh")
Files /dev/fd/63 and /dev/fd/62 are identical
```
[Answer]
# Bash, 6 bytes
```
cat $0
```
Basically.
[Answer]
# UNIX executable loader, 10 bytes
```
#!/bin/cat
```
If you don't care about spam on standard error, you can make it one byte shorter:
```
#!/bin/dd
```
[Answer]
# C, 52
```
s[99];main(){read(open(__FILE__,0),s,99);printf(s);}
```
Of course, this reads the source code and not the compiled program - I assume that's within spec.
[Answer]
# [Vyxal 2.4.0](https://github.com/Lyxal/Vyxal/releases/tag/v2.4.0), 50 bytes
```
`\");VY_print(chr(96)+code.split('\n')[3][15:-4])#
```
Vyxal doesn't have a way to read files, but in v2.4.0 and prior, there was an ACE exploit that allowed for arbitrary python to be executed.
---
### The ACE:
Vyxal is a transpiled language, meaning that every command in a program is converted to some python code, and then all of the python code is combined together and executed.
When pushing a string, all that was done to the string in transpilation was changing `"` to `\\\"`, then appending it to the stack. This meant that a string `\"); #` would become `\\");#`. On its own, this means nothing, but when considered in the transpiled code, it is much more useful.
When viewing the transpiled code (which you can do for any Vyxal program using the `c` flag), you can see that the snippet ``\\"); #` is transpiled to the following python code:
```
stack.append("\\"); #\n")
```
Instead of pushing the string that we told it to, it simply pushed `\`, followed by a comment. In theory, we could put any python code between the `;` and the `#`, which is what we do in this program.
---
### The program:
In this program, the payload (the python code that we actually care about) is the following:
```
VY_print(chr(96)+code.split('\n')[3][15:-4])
```
This has several parts to it, so lets pick it apart bit by bit.
`VY_print` is the printing function that is defined internally in Vyxal. I used this function instead of `print` because it disables the implicit output that Vyxal normally has. This prints the final string, which will hopefully be the same as the program.
When the program is transpiled, the transpiled code is saved in the `code` variable. This variable is used in the program to read the source code, which makes this a cheating quine.
However, the `code` variable also contains a header that initializes a few variables, such as the stack. To combat this, we `split` the code on newlines and get only the fourth line, which is where our code is.
Unfortunately, this line also has the `stack.append...`, and the comment at the end, neither of which are part of our quine. Because of this, we need to take only the 16th through 5th-to-last characters in the string, which we do with `[15:-4]`.
Finally, our code has a backtick at the beginning to start the string, so we add one to the beginning of the output with `chr(96)`, since the ASCII value of ``` is 96.
[Answer]
## Perl, 15 bytes
```
open 0;print<0>
```
Saved 3 bytes thanks to @[ThisSuitIsBlackNot](https://codegolf.stackexchange.com/users/31388/thissuitisblacknot)!
[Answer]
# PHP, 21 Bytes
```
<?=file(__FILE__)[0];
```
`file` reads a file line by line into an array and the file only has one line. This saves a byte in comparison to `readfile(__FILE__)`.
[Answer]
# Perl 6, 20 bytes
```
print slurp $?FILE
```
I haven't worked with Perl 6 very long so I'm not sure if there are any tricks to make this shorter.
[Answer]
# osascript (AppleScript from the command line), ~~40~~ ~~33~~ 32 bytes
```
(read path to me)'s paragraph 1
```
Executing on a file called a with `osascript a`.
Gets the first paragraph (line) of the file and prints it to STDOUT with a trailing newline, therefore the newline in the code.
[Answer]
# Python 2, 32 bytes
There's a newline at the end of the file.
```
print open(__file__).readline()
```
# Python 3, 33 bytes
There's a newline at the end of the file.
```
print(open(__file__).readline())
```
Thanks to [feersum](https://codegolf.stackexchange.com/users/30688/feersum) for catching a problem and supplying `__file__`, [Loovjo](https://codegolf.stackexchange.com/users/34543/loovjo) for a new approach to the Python 2 solution that saved 17 bytes, and [Skyler](https://codegolf.stackexchange.com/users/45727/skyler) for a solution that saved yet another byte and worked in both Python 2 and 3 (pending `print` being a function in Python 3)!
[Doc link for `readline`](https://docs.python.org/2/tutorial/inputoutput.html#methods-of-file-objects)
[Answer]
# Python 2.7, 30 bytes
```
print open(__file__).read(29)  
```
Edit: Just to be clear, the code above is supposed to have a newline at the end as the 30th byte. I'm not familiar with markdown enough to figure out how to display it in the code block. 
I'm using the same trick here as the one in my C submission. This reads the whole source file excluding the trailing newline to account for the additional newline which `print` will append to the output. 
[Answer]
# Batch, ~~9~~ 8 Bytes
```
@type %0
```
Saved a byte thanks to @Joshua
[Answer]
# AutoIt, 34 bytes
Outputs itself to the clipboard:
```
ClipPut(FileRead(@ScriptFullPath))
```
[Answer]
# Ruby, 14
```
$>.<<IO.read$0
```
[Answer]
# Go, ~~111~~ 105 bytes
```
package main
import("io"
."os"
."runtime")
func main(){_,p,_,_:=Caller(0)
f,_:=Open(p)
io.Copy(Stdout,f)}
```
My first code-golf in Go ‚Äì just a few tricks you can use here I guess.
[Answer]
# C, 49 bytes
```
s[];main(){read(open(__FILE__,0),s,48);puts(s);}
```
Edit: To clarify, the 49th byte is a newline. 
This reads the source code minus the newline at the end to account for the newline which `puts` will append to the end of the output. 
[Answer]
## C, 31 bytes
```
main(){system("cat "__FILE__);}
```
[The bash solution](https://codegolf.stackexchange.com/a/62143/3544) is so short, so why not base a C solution on it?
[Answer]
# PowerShell, 39 36 31 25 Bytes
About as tight as I can get it:
`gc $MyInvocation.MyCommand.Path | oh`
Backed by popular demand this has been changed to:
```
gc $PSCommandPath|echo -n
```
prints to host shell current standard output.
[Answer]
# Ruby, 15 bytes
```
$><<IO.read($0)
```
Source: <https://stackoverflow.com/questions/2474861/shortest-ruby-quine>
[Answer]
# Pyth, 25 bytes
```
$import sys$h'e$sys.argv
```
This reads its file name. Essentially, it looks up argv, opens the file corresponding to its last argument, and prints its first line. 
[Answer]
# Mathematica, 16 bytes
```
FilePrint@$Input
```
Run it in [script mode](http://reference.wolfram.com/language/tutorial/WolframLanguageScripts.html). 
[Answer]
## [><>](http://esolangs.org/wiki/Fish), 13 Bytes
```
0:0go:c=?;1+!
```
Tested both on the online and offline interpreters. The `g` command is the closest to being able to read from the source file and if it doesn't count for the purpose of this challenge I'll mark my entry non-competing; I do believe it normally considered "cheating" for quines.
[Try it online.](http://fishlanguage.com/playground)
[Answer]
# Haskell, 63 bytes
For science!
```
import System.Environment
main=getProgName>>=readFile>>=putStr
```
[Answer]
# [Haskell](https://www.haskell.org/), 49 bytes
```
{-#LANGUAGE CPP#-}main=putStr=<<readFile __FILE__
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/v1pX2cfRzz3U0d1VwTkgQFm3NjcxM8@2oLQkuKTI1samKDUxxS0zJ1UhPt7N08c1Pv7/fwA "Haskell ‚Äì Try It Online")
(GHC) Haskell has an extension to use the C preprocessor (commonly used for portability between versions and architectures.) Hopefully self-explanatory.
[Answer]
# [Rust](https://www.rust-lang.org/), 45 bytes
```
fn main(){print!("{}",include_str!(file!()))}
```
[Try it online!](https://tio.run/##KyotLvn/Py1PITcxM09Ds7qgKDOvRFFDqbpWSSczLzmnNCU1vrikSFEjLTMnVVFDU1Oz9v9/AA "Rust ‚Äì Try It Online")
The file macro expands to the file it's invoked in's file path, the include\_str macro expands to a string literal containing the contents of the file at the specified path, and the print macro prints.
[Answer]
# Go, 133 Bytes
> 
> Everyone clear? Go!
> 
> 
> 
```
package main
import("fmt"
"io/ioutil"
"runtime")
func main(){_,f,_,_:=runtime.Caller(0)
s,_:=ioutil.ReadFile(f)
fmt.Print(string(s))}
```
[Answer]
# Node.js, ~~66~~ 63 bytes
```
p=process;p.stdout.write(require('fs').readFileSync(p.argv[1]))
```
Doesn't use `console.log`, which appends a newline.
[Answer]
# Java 8, ~~133~~ 125 Bytes (or ~~150~~ 142 slightly cleaner)
Based on @VoteToClose's answer but choosing Files.copy and thus avoiding the intermediate String creation needed to call System.out:
```
import java.nio.file.*;interface A{static void main(String[]a) throws Exception{Files.copy(Paths.get(A.class.getName()+".java"),System.out);}}
```
or hard-coding the class-name even more:
```
import java.nio.file.*;interface A{static void main(String[] a)throws Exception{Files.copy(Paths.get("A.java"),System.out);}}
```
Cleaned up:
```
import java.nio.file.*;
class A {
    public static void main(String[] a) throws Exception {
        Files.copy(Paths.get("A.java"), System.out);
    }
}
```
[Answer]
# HTML with JavaScript, 115 bytes (doesn't really count)
```
<!DOCTYPE html><html><title>x</title><script>alert(new XMLSerializer().serializeToString(document))</script></html>
```
Does this count? I don't mind, it was fun :)
Technically it doesn't open a file. It's also a well-formed HTML5 document. The XMLSerializer was the only tool which also returned the DOCTYPE portion, but is non-standard. Still, it works on chrome and firefox, and I bet other browsers.
And as a bonus:
# JavaScript, 41 bytes
```
alert(document.currentScript.textContent)
```
[Answer]
# [ùîºùïäùïÑùïöùïü](https://github.com/molarmanful/ESMin/), 2 chars / 6 bytes
```
‚Ñπ‚¨Æ
```
`[Try it here (Firefox only).](http://molarmanful.github.io/ESMin//interpreter.html?eval=false&input=&code=%E2%84%B9%E2%AC%AE)`
The ‚Ñπ function both returns and pushes to the stack the source code. There is automatic outputting, so the contents of the stack will be outputted. Therefore, the source code will be outputted.
]