Solved

shell script

Posted on 2014-02-13
14
329 Views
Last Modified: 2014-03-20
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
Comment
Question by:ittechlab
  • 4
  • 3
  • 3
  • +3
14 Comments
 
LVL 31

Accepted Solution

by:
farzanj earned 99 total points
ID: 39857497
version=$(perl -v | grep -Po '\d+\.\d+\.\d+')
if [[ $version == "5.8.9" ]]
then
     echo yes
fi

Open in new window

0
 

Author Comment

by:ittechlab
ID: 39857517
can you please explain this first line i am not sure how \d+ works here.
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 99 total points
ID: 39857526
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
 

Author Comment

by:ittechlab
ID: 39857532
how do i check if this 32 bit or 64 bit as well?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39857551
file $(which perl)

/usr/bin/perl: ELF 64-bit LSB executable, x86-64,  ... ...
0
 

Author Comment

by:ittechlab
ID: 39857616
how do i check using script?
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39857638
if file $(which perl) |grep -q "64-bit"; then echo yes; fi
0
 
LVL 48

Expert Comment

by:Tintin
ID: 39857656
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
 
LVL 37

Assisted Solution

by:Gerwin Jansen
Gerwin Jansen earned 98 total points
ID: 39857757
>> 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
 
LVL 26

Assisted Solution

by:skullnobrains
skullnobrains earned 99 total points
ID: 39886620
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
 
LVL 37

Expert Comment

by:Gerwin Jansen
ID: 39931829
Why the B grade? You got perfect answers and some additional explanation as well. This should be graded A.
0
 

Author Comment

by:ittechlab
ID: 39931837
How do I change it now.
0
 
LVL 37

Expert Comment

by:Gerwin Jansen
ID: 39931919
You can use the Request Attention button above and state you want to change the grade.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AWS CLI - Issue with name display 2 51
nagios 1 22
Video Streaming 6 56
Oracle 10g standard edition server with 4 processors 3 38
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now