zl程序教程

您现在的位置是:首页 >  系统

当前栏目

linux shell实现go.mod迁移后版本号的更新问题(技能点:sed删除行自定义分隔符;文件的过滤后遍历)

2023-09-14 09:01:52 时间
#!/bin/bash

# 判断当前目录是否存在go.mod文件
if [ -f "$1/go.mod" ];then
    # 遍历go.mod并过滤module开头的行
    for line in $(cat $1/go.mod | grep -v "module");
    do
        # 筛选出含git.zxl.com的行
        if [[ $line =~ git.zxl.com* ]];then
            # 先删除
            sed -i "\#$line#d" $1/go.mod
            # 再进行go get
            cd $1
            go get $line@master
            go mod tidy
            cd ..
        fi
    done
fi