Last active
November 30, 2019 16:08
-
-
Save scvalex/5360004 to your computer and use it in GitHub Desktop.
A real quine in Bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
T='#!/bin/bash | |
Q=$(printf "\x27") # A literal single quote | |
echo "$T" | head -n2 - | |
echo T=$Q"$T"$Q | |
echo "$T" | tail -n6 -' | |
Q=$(printf "\x27") # A literal single quote | |
echo "$T" | head -n2 - | |
echo T=$Q"$T"$Q | |
echo "$T" | tail -n6 - |
Very good! I had to be very careful copying this -- copy and paste got it wrong (but created a different quine).
I preferred a slight change, to use the "-n+NUM" form of tail, to match the argument to head, and change the shebang to match my preferred usage, and wound up with:
#!/usr/bin/env bash
# As seen at https://gist.github.com/scvalex/5360004
T='#!/usr/bin/env bash
# As seen at https://gist.github.com/scvalex/5360004
Q=$(printf "\x27") # A literal single quote
echo "$T" | head -n3 -
echo T=$Q"$T"$Q
echo "$T" | tail -n+3 -'
Q=$(printf "\x27") # A literal single quote
echo "$T" | head -n3 -
echo T=$Q"$T"$Q
echo "$T" | tail -n+3 -
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
echo $BASH_COMMAND
:)