4

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

dubiousjim
  • 4,722
  • 1
  • 36
  • 34
Rob
  • 3,687
  • 2
  • 32
  • 40

1 Answers1

3

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 } '

SiegeX
  • 135,741
  • 24
  • 144
  • 154