If u type
--- rpm -q glibc
--- glibc-2.3.3-74
I want to extrac (2.x) from the string and store in a variable. How can I do that.
I have started something like this... Its a shell script.. can anybody help me out..
rakesh
More Articles by anonymous
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.
We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.
Click here to add your comments
Thu Jul 27 17:13:48 2006: TonyLawrence
If I'm understanding you correctly, you want:
rpm -q glibc | sed 's/glibc-\(...\).*/\1/'
Fri Jul 28 11:56:04 2006: anonymous
Hey Tony.... Thats great man. Aceppt a haertly thanks from me
Mon Jul 31 10:50:35 2006: anonymous
Tony, I would like to bug you a bit more.... Here is what I am trying to do..
#!/bin/bash
UNAME_MACHINE=`uname -m`
UNAME_KERNAL=`uname -s`
GLIB_QUERY=`rpm -q glibc`
GLIBC_VERSION_INFO=`echo ${GLIB_QUERY} | sed 's/glibc-\(...\).*/\1/'`
GLIBC_VERSION=0
echo $GLIBC_VERSION_INFO
if [ $GLIBC_VERSION_INFO -ge 2.3 ]; then
GLIBC_VERSION=30
elif [ $GLIBC_VERSION_INFO -lt 2.2 ]; then
GLIBC_VERSION=21
else
GLIBC_VERSION=0
fi
echo $GLIBC_VERSION
if [ $GLIBC_VERSION -eq 0 ]
then
echo $UNAME_MACHINE"_"$UNAME_KERNAL
else
echo $UNAME_MACHINE"_"$UNAME_KERNAL"_"$GLIBC_VERSION
Mon Jul 31 10:51:49 2006: anonymous
But it is cribbing with the below errors :-
./platform.sh: line 12: [: 2.3: integer expression expected
./platform.sh: line 14: [: 2.3: integer expression expected
Mon Jul 31 11:40:44 2006: TonyLawrence
Read the man page for "test". You are trying to compare strings to integers with an integer comparison operator. You need to use string comparion (=, <, >) and put your numbers in quotes to make them strings.
Mon Jul 31 12:46:00 2006: anonymous
But with string only = and != operators are allowed!!
Is there something like typecast as well for scripting langauges, I would prefer to typecast string to integer.
Mon Jul 31 13:03:59 2006: TonyLawrence
If you'd prefer what you don't have, use a language that has what you prefer.
Mon Jul 31 13:17:47 2006: anonymous
Aah!! I was expecting a terse reply from you... Anyway thanks man. I would surely explore.... Thanks
Mon Jul 31 15:49:07 2006: TonyLawrence
Sorry to be terse, but really: I don't write anything but one liners in shell - if it's at all complicated - even just a little - I use Perl.
You should use a language that you like..
Tue Aug 1 08:50:44 2006: anonymous
Tony, I am very impressed. You are a great human-being. I have never expected an answer from you. And you are very humble. In our mother-tongue(HINDI), there is proverb.. which means "knowledge makes a person humble" and so you are!!
Great job dude.... carry on!!
Tue Aug 1 10:41:15 2006: TonyLawrence
Well, I shouls have also mentioned that bash does let you typecast strings to integers. See the man or info pages and look at "declare".
Don't miss responses! Subscribe to Comments by RSS or by Email
Click here to add your comments
If you want a picture to show with your comment, go get a Gravatar