linux - 使用 makefile 脚本将返回值的值增加 1

标签 linux bash shell makefile sh

我用以下格式返回号码

v0.0.1

所以在这种情况下我需要将数字更改为

v0.0.2

如果我有

v0.0.9

我想改成

v0.1.0

等等自己...每次增加一个

我试过的是以下内容

awk -F. '{$NF+=1; OFS="."; print $0}

哪个不起作用(给出相同的值),可能是什么问题?

我在 VERSION=git describe --tags --abbrev=0 | 之前使用awk-F。 '{$NF+=1; OFS=".";打印 $0}'

这行不通...

更新

当我尝试使用 james 的代码时,我在没有 dots 和没有 v

的情况下得到了增加的值

enter image description here

最佳答案

使用分隔符和重建记录:

$ echo 0.0.9 | 
awk '
BEGIN {
    FS="."                  # set the separators
    OFS=""
}
{
    sub(/^v/,"")            # remove the v
    $1=$1                   # rebuild record to remove periods
    $0=sprintf("%03d",$0+1) # zeropad the number after adding 1 to it
}
END {
    FS=""                   # reset the separators 
    OFS="."
    $0=$0                   # this to keep the value in $0
    $1=$1                   # rebuild to get the periods back
    print "v" $0            # output
}'
v0.1.0

似乎适用于 9.9.9 -> 1.0.0.0。

关于linux - 使用 makefile 脚本将返回值的值增加 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49691371/

相关文章:

linux - 如何找到大于可变时间戳的所有 ERROR 日志?

linux - 可启动的 Qt-Linux 应用程序

bash - 从 Matlab 中运行 unix 命令时忽略用户输入

linux - 为什么/usr/bin/timeout 会杀死整个管道?

linux - 计算大文件中的行数

linux - ssh: 用户不允许 shell 不存在

java - CSV 到 H2 - 字符编码不匹配

linux - 链路电源管理中的 L2 状态

Bash- 将变量转换为人类可读的格式(KB、MB、GB)

linux - 如何在 Linux Bash 脚本文件中使用 'sed' 来注释掉带有制表符间距的特定行?