Enable re-interval in gawk script

709 Views Asked by At

I create executable scripts for gawk by using the following #!:

#!/usr/bin/gawk -f

However if I want to enable interval regular expressions I cannot seem to add --re-interval or -W re-interval in the #!.

#!/usr/bin/gawk --re-interval -f
#Above doesn't work

Is there a way to have a script activate this option without command line arguments, or a better way to enter the arguments so it works?

I am using cygwin if that matters for your solution

1

There are 1 best solutions below

0
On BEST ANSWER

This isn't possible. See http://hibernia.jakma.org/~paul/awk-faq.html#script-args for the reason and an alternative.

How do I pass options to AWK in a bang-path?

Short answer is that you can't, because the kernel won't parse a bang-path past the name of the script. The rest of the line is passed as a single string, in the second argument. I.e. this won't work:

#!/path/to/gawk --posix --re-interval -f

....awk script..

Instead, use a shell script, e.g.:

#!/bin/bash

gawk --posix --re-interval -v foo=$1 ' BEGIN { print foo } '