【发布时间】:2021-09-19 05:52:30
【问题描述】:
我想用awk命令获取gcc版本,但是返回的字符串是空的。
$ gcc --version
gcc (GCC) 11.1.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gcc --version | head -1 | awk '{for(i=1;i<=NF;i++){ if(match($i,/^[0-9]\.[0-9]\.[0-9]$/)) {print $i; exit 0}}}'
$
不知道为什么会失败。有什么想法吗?
【问题讨论】: