• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 338
  • Last Modified:

shell script

This is perl, v5.8.9 built for i386-thread-multi

Copyright 1987-2008, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

I want to grep the version and compare to make sure it is 5.8.9.  How do we do that in shell script
0
ittechlab
Asked:
ittechlab
  • 4
  • 3
  • 3
  • +3
4 Solutions
 
farzanjCommented:
version=$(perl -v | grep -Po '\d+\.\d+\.\d+')
if [[ $version == "5.8.9" ]]
then
     echo yes
fi

Open in new window

0
 
ittechlabLinux SupportAuthor Commented:
can you please explain this first line i am not sure how \d+ works here.
0
 
woolmilkporcCommented:
The usual one-liner with awk:

perl -v | awk -F"This is perl, v| built for" '/built for/ {if($2~"5.8.9") print "yes"}'
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ittechlabLinux SupportAuthor Commented:
how do i check if this 32 bit or 64 bit as well?
0
 
woolmilkporcCommented:
file $(which perl)

/usr/bin/perl: ELF 64-bit LSB executable, x86-64,  ... ...
0
 
ittechlabLinux SupportAuthor Commented:
how do i check using script?
0
 
woolmilkporcCommented:
if file $(which perl) |grep -q "64-bit"; then echo yes; fi
0
 
TintinCommented:
wmc, your check doesn't work for all versions, eg:

$ perl -v

This is perl 5, version 16, subversion 2 (v5.16.2) built for darwin-thread-multi-2level
(with 3 registered patches, see perl -V for more detail)

Copyright 1987-2012, Larry Wall
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
>> can you please explain this first line i am not sure how \d+ works here.

\d+ is part of the regular expression that is grepped for, it means one or more digits (numbers), pattern '\d+\.\d+\.\d+' matches 1.2.3 or 5.8.9 or 10.20.30

\. is a literal dot (.) in the pattern
0
 
skullnobrainsCommented:
if perl -v | grep -f 'v5.8.9 ' >/dev/null
then echo happy
else echo unhappy
fi

if you want it to check for i386 as well

if perl -v | grep 'v5\.8\.9[[:space:]].*i386' >/dev/null
then echo happy
else echo unhappy
fi
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
Why the B grade? You got perfect answers and some additional explanation as well. This should be graded A.
0
 
ittechlabLinux SupportAuthor Commented:
How do I change it now.
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
You can use the Request Attention button above and state you want to change the grade.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now