bash 使用bash从subversion获取修订号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2299593/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 18:57:16  来源:igfitidea点击:

using bash to get revision number from subversion

bashshell

提问by user151841

I want to write a shell script in bash to deploy websites from an svn repository. When I deploy a website, I name the exported directory website_name-Rrevision_number. I'd like the bash script to automatically rename the exported directory, so it needs to learn the current revision number from the export directory. If I run

我想用 bash 编写一个 shell 脚本来从 svn 存储库部署网站。当我部署网站时,我将导出的目录命名为website_name-R revision_number。我希望 bash 脚本自动重命名导出的目录,因此它需要从导出目录中了解当前的修订号。如果我跑

$> svn info http://svn-repository/trunk

Path: trunk
URL: http://svn-repository/mystery/trunk
Repository Root: http://svn-repository/mystery
Repository UUID: b809e6ab-5153-0410-a985-ac99030dffe6
Revision: 624
Node Kind: directory
Last Changed Author: author
Last Changed Rev: 624
Last Changed Date: 2010-02-19 15:48:16 -0500 (Fri, 19 Feb 2010)

The number after the string Revision:is what I want. How do I get that into a bash variable? Do I do string parsing of the output from the svn infocommand?

字符串后面的数字Revision:是我想要的。我如何将其放入 bash 变量中?我是否对svn info命令的输出进行字符串解析?

回答by oefe

Use svnversion. This will output the revision number/range with minimal additional cruft

使用svnversion。这将输出修订号/范围,并且附加最少

回答by Paul Tomblin

REVISION=`svn info http://svn-repository/trunk |grep '^Revision:' | sed -e 's/^Revision: //'`

It's simple, if inelegant.

这很简单,如果不优雅。

回答by ghostdog74

just use one awk command. much simpler as well.

只需使用一个 awk 命令。也简单得多。

var=$(svn info http://svn-repository/trunk | awk '/^Revision:/{print }')

回答by bartolomeo_n

Parsing the 'Revision' string is not portable across different locales. Eg. with my locale it is like:

解析 'Revision' 字符串不能跨不同语言环境移植。例如。我的语言环境就像:

...
Wersja: 6583
Rodzaj obiektu: katalog
Zlecenie: normalne
Autor ostatniej zmiany: ...
Ostatnio zmieniona wersja: 6583
Data ostatniej zmiany: 2013-03-21 11:33:44 +0100 (czw)
...

You don't wanna parse that :)

你不想解析那个:)

So, the best approach is to use 'svnversion' as oefe suggested. This is the tool mentioned for this purpose.

因此,最好的方法是使用 oefe 建议的“svnversion”。这是为此目的提到的工具。

回答by Jaeyoung Chun

Without using grep or awk:

不使用 grep 或 awk:

REVISION=`svn info --show-item=revision | sed 's/ //g'`

sedat the end is just to remove the trailing whitespace.

sed最后只是删除尾随的空格。

回答by meagar

svn info http://svn-repository/trunk | grep Revision | tr -d 'Revison: '

Spits out the revision Use backticks in your shell script to execute this and assign the results to a variable:

吐出修订版 在您的 shell 脚本中使用反引号来执行此操作并将结果分配给一个变量:

REVISION=`svn info http://svn-repository/trunk | grep Revision | tr -d 'Revison: '`

回答by swestrup

There are probably a dozen different ways to do this, but I'd go with something simple like:

可能有十几种不同的方法可以做到这一点,但我会采用一些简单的方法,例如:

revision="$(svn info http://svn-repository/trunk | grep "^Revision:" | cut -c 11-)"

回答by Avincoder

This will give you the head revision number

这将为您提供头部修订号

svn info -r 'HEAD' | grep Revision | egrep -o "[0-9]+"

egrep is extended grep.

egrep 是扩展的grep。

回答by sai

REVISION=$(svn info http://svn-repository/trunk |grep '^Revision:' | sed -e 's/^Revision: //p')
echo $REVISION