Artificial intelligent assistant

Pass options to AWK script bypassing AWK Can I get arguments that happen to be AWK options passed directly to a pure AWK script? Example script: #!/usr/bin/env -S awk -f BEGIN { if (ARGV[1] == "-h") print "whoop" } I want `./myscript -h` to print whoop. But AWK gets the -h first and prints its usage instead. Running `./myscript -- -h` works but I can't get -- working in the shebang because of the -f. I know I could use a shell script with AWK in instead.

For the sake of the challenge, it could be done with the FreeBSD `env` or with GNU env >= 8.30 (already assumed by the OP) in a shebang:


#! /usr/bin/env -S sh -c 'exec awk -f "$0" -- "$@"'
BEGIN { for(i = 1; i < ARGC; i++) print ARGV[i] }



./myscript -h 1 2 3
-h
1
2
3


It doesn't mean that it's a good idea, though.

You could try this, instead:


#! /bin/sh
BEGIN { 2>"/dev/null"
exec awk -f "$0" "--" "$@"
}
BEGIN { for(i = 1; i < ARGC; i++) print ARGV[i] }


This assumes that you don't have a `BEGIN` command in your `PATH`.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 1c6a3a49991972c338845d137c0d3dd2