gpt4 book ai didi

linux - 使用 shell 脚本更新版本

转载 作者:太空宇宙 更新时间:2023-11-04 12:31:06 25 4
gpt4 key购买 nike

#include  "calcmarks.h"

// calcmarks, version 1, released Thu Mar 23 13:16:49 WST 2017

int main(int argc, char *argv[])
{
int nmarks = 0;

if(argc == 1) {
nmarks += readmarks(stdin);

不管这段代码是什么,我想要的是一个shellscript来更新和版本。完成shellscript后,上面的注释将变成

//calcmarks,版本 2,已发布(执行脚本时)

尝试执行以下操作,但没有成功。

a=$(date) 
sed -i "_bak" s'/Thu Mar 23 13:16:49 WST 2017/$a/g' "calcmarks.c"

最佳答案

这里是执行该技巧的命令列表。注意:如果您使用的是不同的版本编号系统(2.1、2.1.1 等),则需要稍微更改一下。

prev_version=$(sed -n '\%.*// calcmarks, version %!d;s///;s/ .*//p' "$file")
new_version=$((prev_version+1))
curr_date=$(date "+%a %b %d %H:%M:%S %Z %Y")
sed -i -e "s#\(// calcmarks, version \)${prev_version}.*#\1${new_version}, released ${curr_date}#g" "$file"

关于linux - 使用 shell 脚本更新版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43247014/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com