If the program is Python
The question is "How to compare a program's version in a shell script?" It givesnot gcc as an example. Somespecific though many answers are gcc specific.
And* Even the excellent general ones withanswers using cut -d" " stillwill fail for older Python because prior to v3.4, python --version wrote to stderr instead of stdout. (!!)
Here is a short bash command to check that your Python is at least v3.8 (or whatever you use), that uses Python to avoid both stderr issues and the gyrations involved with *sh string comparison.
python -c "import sys; sys.version_info < (3,8) and sys.exit(1)" \
&& echo "At least v3.8!" || echo "Old version. Do not use."
Note that the version is a Python tuple like (3, 8, 18, "final", 0) so if you needed at least v3.8.13, you would use (3, 8, 13).
My use case: stop pip if Python is too old, before I accidentally install hundreds of packages for the wrong environment.
$ python -V \
> && python -c "import sys; sys.version_info < (3,8) and sys.exit(1)" \
> && echo "Python version OK" \
> && echo "UPDATING PIP..." \
> && python -m pip install --upgrade pip \
> && echo "UPDATING MYPACKAGE..." \
> && python -m pip install .[dev] \
> || echo "Old Python or other error."
Python 2.7.18
Old Python or other error.
* The question is: "How to compare a program's version in a shell script?" It gives gcc as an example but is not limited to gcc.