How to use multiple arguments for awk with a shebang (i.e. #!)?

前端 未结 10 882
小蘑菇
小蘑菇 2020-11-22 17:42

I\'d like to execute an gawk script with --re-interval using a shebang. The \"naive\" approach of

#!/usr/bin/gawk --re-interval -f
... awk scri         


        
10条回答
  •  感动是毒
    2020-11-22 18:10

    Just for fun: there is the following quite weird solution that reroutes stdin and the program through file descriptors 3 and 4. You could also create a temporary file for the script.

    #!/bin/bash
    exec 3>&0
    exec <<-EOF 4>&0
    BEGIN {print "HALLO"}
    {print \$1}
    EOF
    gawk --re-interval -f <(cat 0>&4) 0>&3
    

    One thing is annoying about this: the shell does variable expansion on the script, so you have to quote every $ (as done in the second line of the script) and probably more than that.

提交回复
热议问题