Awk script header: #! / Bin / bash or #! / Bin / awk -f?

The awk file, for example example.awk, should have a header #!/bin/bashor #!/bin/awk -f?

The reason for my question is that if I try this command in the console, I get the correct .txt file with a "line of text":

 awk 'BEGIN {print "line of text"}' >> file.txt

but if I try to execute the following file with. /example.awk:

#! /bin/awk -f
awk 'BEGIN {print "line of text"}' >> file.txt

it returns an error:

$ ./awk-usage.awk
awk: ./awk-usage.awk:3: awk 'BEGIN {print "line of text"}' >> file.txt
awk: ./awk-usage.awk:3:     ^ invalid char ''' in expression

If I change the title to #!/bin/bashor #!/bin/sh, it works.

What is my mistake? What is the reason for this?

+3
source share
2 answers

awk, #!/bin/bash. #!/bin/awk, awk awk (, BEGIN {print "line of text"}), file awk (print ... >> file).

awk -f , awk script, .

+7

script script, awk.

#! /bin/sh /bin/sh - . #! /bin/awk -f, awk, ,

/bin/awk -f awk 'BEGIN {print "line of text"}' >> file.txt 
+2

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


All Articles