2

When curl --version is executed on the command line of a VM running Ubuntu 18.04 this is displayed in the terminal:

curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.1 zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Release-Date: 2018-01-24
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL 

How do I change the command so that only 7.58.0 is displayed?

Kulfy
  • 18,154
knot22
  • 149

1 Answers1

5

With a little modification.

:~$ curl --version | head -n 1 | awk '{ print $2 }'
7.58.0

head -n 1 tells shell to print the first line of output.

awk '{ print $2 }' will print the second column.


You can also tell awk to print the second column of the first line, using NR built-in variable.
:~$ curl --version | awk 'NR==1{print $2}'
7.58.0

NR==1 tells awk to print the first line of the output.

{ print $2 } will print the second column.

Liso
  • 15,677