17

If I want to know the version of awk I get the following:

$ awk --version
awk: not an option: --version

Checking in man awk I see that my awk is

mawk - pattern scanning and text processing language

fedorqui
  • 1,877
  • 1
  • 16
  • 36
  • --version is something the GNU invented for their own commands, it is not part of POSIX and most commands don't support --version. GNU awk does however, and awk --version does something sensible on my system. fedorqui's distribution uses something other than GNU awk by default. – wingedsubmariner Sep 18 '13 at 13:22
  • @wingedsubmariner that's an interesting information you gave. Thanks! My awk is `mawk`, hence the inexistence of `version`. – fedorqui Sep 18 '13 at 14:27

2 Answers2

19

In this case, man awk shows us:

-W version

mawk writes its version and copyright to stdout and compiled limits to stderr and exits 0.

In my case,

$ awk -W version
mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan

compiled limits:
max NF             32767
sprintf buffer      2040
fedorqui
  • 1,877
  • 1
  • 16
  • 36
  • 1
    my version is showing 2020 January and it still wouldn't support `-v` or `--version` on Linux. On the Mac, it is showing a 2007 version but it supports `--version`. I suppose `awk` is important enough that they can do whatever they want, and it is coherent with what I feel at work: if you are easy, you get looked down and stepped on. If you are difficult, you get respected – nonopolarity Dec 17 '20 at 00:55
  • @nonopolarity what Awk are you using? – fedorqui Dec 17 '20 at 08:16
  • I check my Big Sur (on M1) again, and it showed `20200816` The one that showed 2007 was Mojave. The one that needed the `-W` was showing `mawk` – nonopolarity Dec 17 '20 at 16:37
6

I try to be more general.

awk -Wversion 2>/dev/null || awk --version

works whether awk invokes mawk, gawk or original-awk available for Debian/Ubuntu Linux. Note that -W and version have to be concatenated so that original-awk does not think version is a program. In Ubuntu Linux you can use sudo update-alternatives --config awk to see and to choose the implementation that is invoked by the command awk.

jarno
  • 313
  • 3
  • 12
  • I don't know how standard it is to accept the concatenated option, but it is not necessary use it in my experience: `awk -W version /dev/null|awk '{print $0;nz=1}END{if(!nz)exit 1}' || awk --version` or alternatively `(s=$(awk -W version /dev/null); if [ -n "$s" ]; then printf "$s\n"; else awk --version; fi)` – jarno Sep 05 '15 at 16:39