【问题标题】:Get android:versionName with shell command使用 shell 命令获取 android:versionName
【发布时间】:2011-11-26 02:07:39
【问题描述】:

我想使用 shell 命令从 AndroidManist.xml 文件中获取 versionName。 我一直在尝试使用 grep 和 with:

 grep versionName ./AndroidManifest.xml

我得到了这条线:

android:versionName="1.0">

是否有可能以某种方式将其缩小到 1.0

提前致谢

【问题讨论】:

    标签: android shell command-line


    【解决方案1】:

    试试这个:

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

    您可能希望将其放入文件中:

    例如: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";
    }
    

    然后只需 chmod 755 VersionNumber.pl 并将其与 VersionNumber.pl AndroidManifest.xml 一起使用

    【讨论】:

    • 正是我想要的。谢谢老兄。
    【解决方案2】:

    可以从您最初的建议中得出一个较短的版本:

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

    【讨论】:

    • grep versionCode AndroidManifest.xml |剪切 -d\" -f2
    • 要考虑的一件事是,当您将 versionCode="" 和 versionName="" 都放在同一行时。一个在另一个之前。
    猜你喜欢
    • 2015-03-31
    • 1970-01-01
    • 1970-01-01
    • 2013-05-09
    • 2011-12-04
    • 2023-03-13
    • 2013-05-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多