简体   繁体   English

awk shebang不起作用

[英]awk shebang doesn't work

I have a simple awk program: 我有一个简单的awk程序:

#!/usr/bin/awk -f
BEGIN {print "work already!"}

If I run it as: 如果我运行它:

awk -f panic

on the (osx) terminal it works. 在(osx)终端上它可以工作。 But it fails if I try running it as a script: 但是如果我尝试将其作为脚本运行它会失败:

. panic
-bash: BEGIN: command not found

I checked the location of awk using which awk and it is indeed located at /usr/bin/awk . 我检查了awk使用which awk的位置,它确实位于/usr/bin/awk Any ideas why it isn't working? 任何想法为什么它不起作用?

Run it as ./panic , not . panic 运行它为./panic ,而不是. panic . panic , as the latter is the same as running source panic , which won't do what you want. . panic ,因为后者与运行source panic相同,这不会做你想要的。 See man source man source

To run a file as a script you must type: 要将文件作为脚本运行,您必须键入:

./<script>

Edit : 编辑

As pointed by William Pursell, . 正如William Pursell指出的那样. is not an alias for source , but the exact contrary. 不是source的别名,但恰恰相反。

. is not an alias for source. 不是源的别名。 . is the sh standard command for running another script inside the current shell. 是用于在当前shell中运行另一个脚本的sh标准命令。 source is a command that originated in csh and was adopted by many sh clones as an alias for .. If source is to be viewed as anything but an abomination, it is an alias for ., not the other way around. source是一个源自csh的命令,被许多sh克隆用作别名。如果源被视为除了憎恶之外的任何东西,它是。的别名,而不是相反。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM