打印不含 license/copyright 信息的 GCC 版本
Print GCC version without license/copyright information
我正在编写 Makefile 并设置 Docker 图像以在 CI 环境中构建。在这些不同的脚本中,我想打印我正在设置的工具的版本 and/or 使用。
gcc --version
显示简单的版本号和一些版权和许可信息。我机器上的示例输出:
$ gcc --version
gcc.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 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.
是否有更简单的方法来获取版本信息而不解析此输出?
这里有两个想法:
1。请改用 -dumpversion
选项。它应该打印一个漂亮、简洁的版本号。无需进一步解析即可在任何平台上工作。
$ gcc -dumpversion
8.1.0
$ arm-none-eabi-gcc -dumpversion
8.3.1
编辑 2021-01-17:
我最近发现在早期的 GCC 版本中 -dumpversion
只显示主要版本,而 -dumpfullversion
打印所有 Major.Minor.Patch 版本号。如果以上方法不适合您,请尝试 -dumpfullversion
。
2。在 Linux 上(或 Bash/MSYS 代表 Windows)你有 head
抓住第一行
$ gcc --version | head -n1
gcc.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
$ arm-none-eabi-gcc --version | head -n1
arm-none-eabi-gcc.exe (GNU Tools for Arm Embedded Processors 8-2019-q3-update) 8.3.1 20190703 (release) [gcc-8-branch revision 273027]
我正在编写 Makefile 并设置 Docker 图像以在 CI 环境中构建。在这些不同的脚本中,我想打印我正在设置的工具的版本 and/or 使用。
gcc --version
显示简单的版本号和一些版权和许可信息。我机器上的示例输出:
$ gcc --version
gcc.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 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.
是否有更简单的方法来获取版本信息而不解析此输出?
这里有两个想法:
1。请改用 -dumpversion
选项。它应该打印一个漂亮、简洁的版本号。无需进一步解析即可在任何平台上工作。
$ gcc -dumpversion
8.1.0
$ arm-none-eabi-gcc -dumpversion
8.3.1
编辑 2021-01-17:
我最近发现在早期的 GCC 版本中 -dumpversion
只显示主要版本,而 -dumpfullversion
打印所有 Major.Minor.Patch 版本号。如果以上方法不适合您,请尝试 -dumpfullversion
。
2。在 Linux 上(或 Bash/MSYS 代表 Windows)你有 head
抓住第一行
$ gcc --version | head -n1
gcc.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
$ arm-none-eabi-gcc --version | head -n1
arm-none-eabi-gcc.exe (GNU Tools for Arm Embedded Processors 8-2019-q3-update) 8.3.1 20190703 (release) [gcc-8-branch revision 273027]