Enable re-spacing in gawk script

I am creating executable scripts for gawk using the following # !:

#!/usr/bin/gawk -f

However, if I want to include interval regular expressions, I cannot add --re-interval or -W re-interval to # !.

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

Is there a way for a script to activate this option without command line arguments, or is there a better way to enter arguments to make it work?

I use cygwin if it is important for your solution

+4
source share
1 answer

It's impossible. See http://hibernia.jakma.org/~paul/awk-faq.html#script-args for reason and alternative.

How to pass AWK parameters to the bach path?

The short answer is that you cannot, because the kernel will not parse bang-path missed the script name. The rest of the line is passed as one line, in the second argument. That is, this will not work:

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

.... awk script ..

Use a shell script instead, for example:

#!/bin/bash

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

+3
source

Source: https://habr.com/ru/post/1342369/


All Articles