Nan Xiao
Nan Xiao

Reputation: 17477

Why does the command only work in gawk?

I have 2 hosts: one is running Linux, while the other is OmniOS.

The awk on Linux is gawk:

[root@localhost ~]# which awk
/bin/awk
[root@localhost ~]# ls -lt /bin/awk
lrwxrwxrwx. 1 root root 4 Jan 22  2014 /bin/awk -> gawk

And running the following command is OK:

[root@localhost  ~]# awk 'function print_name_and_age(name, age) { print name" is "age" old" } {print_name_and_age($1, $2)}'
Mark 12
Mark is 12 old

I think awk on OmniOS is nawk, but not sure:

root@localhost:/root# which awk
/usr/bin/awk
root@localhost:/root# ls -lt /usr/bin/awk
-r-xr-xr-x   2 root     bin        90664 Apr  3 01:17 /usr/bin/awk
root@localhost:/root# awk
awk: Usage: awk [-Fc] [-f source | 'cmds'] [files]

But executing the same command is error:

root@localhost:/root# awk 'function print_name_and_age(name, age) { print name" is "age" old" } {print_name_and_age($1, $2)}'
awk: syntax error near line 1
awk: bailing out near line 1

I can't figure out the root cause, could anyone give any clues?

Upvotes: 1

Views: 143

Answers (0)

Related Questions