开发者

Get android:versionName with shell command

I want to get the versionName from the AndroidManist.xml file with a shell command. I've been trying to use grep and with:

 grep versionName ./AndroidManifest.xml

I'm getting this line:

android:versionName="1.0"&开发者_开发知识库gt;

Is it possible to narrow it down to 1.0 somehow?

Thanks in advance


Try this :

perl -e 'while($line=<>) { if ($line=~ /versionName\s*=\s*"([^"]+)"/) { print "$1\n";}}' <AndroidManifest.xml

You may want to put this into a file :

Ex: VersionNum.pl

#!/usr/bin/perl

#get the filename from command line
$file = shift or die;

#open the file and read it into $lines var
open(IN,$file) or die;
$lines=join("",<IN>); 
close(IN);

#search the $line var for match and print it
if ($lines =~ m/android:versionName\s*=\s*"([^"]+)"/mgs)  {
   print "$1\n";
}

Then simply chmod 755 VersionNumber.pl and use it with VersionNumber.pl AndroidManifest.xml


A shorter version could be derived from your original suggestion:

grep versionCode AndroidManifest.xml | sed -e 's/.*versionName\s*=\s*\"\([0-9.]*\)\".*/\1/g'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜