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

前端 未结 10 829
小蘑菇
小蘑菇 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 17:45

    Under Cygwin and Linux everything after the path of the shebang gets parsed to the program as one argument.

    It's possible to hack around this by using another awk script inside the shebang:

    #!/usr/bin/gawk {system("/usr/bin/gawk --re-interval -f " FILENAME); exit}
    

    This will execute {system("/usr/bin/gawk --re-interval -f " FILENAME); exit} in awk.
    And this will execute /usr/bin/gawk --re-interval -f path/to/your/script.awk in your systems shell.

提交回复
热议问题