When I execute this script , ./cat-itself.sh it prints itself to stdout, without me having to give it any positional arguments explicitly from the terminal:
#!/usr/bin/bash
cat "$0"
How do I acomplish the same in Awk, Gawk specifically? My attempt is this
#!/usr/bin/awk -f
{
print
}
but there are two issues with this:
1. It prints to stdout anything you give it as a positional parameter, e.g. ./cat-itself.awk cat-itself.awk
2. It requires a positional parameter to print anything to stdout. I want a script
that would work when run like so ./cat-itself.awk
With
gawk(although notgawkspecific) you could get the filename with this solution suggested by Ed Morton, and then you could usegetlineto print the contents of the file:Alternatively, you could also run a
systemcommand to callcat: