简单的awk脚本,不带参数或输入文件

时间:2022-12-24 16:05:48

I am trying to write a simple awk script that doesn't use any file input arguments or anything. I only tested it writing a hello world program so far:

我试图写一个简单的awk脚本,不使用任何文件输入参数或任何东西。到目前为止我只测试了编写一个hello world程序:

#!/usr/bin/awk
BEGIN{}
{print "hello"}
END{}

I get an error awk: 1: unexpected character '.' when I try to run it through terminal using: ./program.awk Why is this happening? Thank you

我得到一个错误awk:1:意外字符'。'当我尝试通过终端运行它时:./ program.awk为什么会发生这种情况?谢谢

1 个解决方案

#1


2  

Add -f to end of shebang line like this to tell awk that the script follows:

将-f添加到shebang行的末尾,告诉awk该脚本如下:

#!/usr/bin/awk -f

Also, as you have no input, put the print inside BEGINblock:

此外,由于您没有输入,请将打印件放在BEGINblock中:

BEGIN {print "Hi"}

#1


2  

Add -f to end of shebang line like this to tell awk that the script follows:

将-f添加到shebang行的末尾,告诉awk该脚本如下:

#!/usr/bin/awk -f

Also, as you have no input, put the print inside BEGINblock:

此外,由于您没有输入,请将打印件放在BEGINblock中:

BEGIN {print "Hi"}