如何做一个bash foreach csv字段为'git submodule add' [英] How to do a bash foreach csv field to 'git submodule add'

查看:154
本文介绍了如何做一个bash foreach csv字段为'git submodule add'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何编写Bash和googling一段时间后,我没有更好的位置,以实现我需要的。
我有一个csv文件,其中包含git子模块列表及其在超级项目中的路径:

  git://github.com/demo/git-repo.git,extensions / git-repo 
git://github.com/demo/another-repo.git,extensions / another-repo

我想要一个bash脚本读取文件的每一行, (用逗号分隔)成以下命令

  git submodule add $ 1 $ 2 

$ 1 是git:// part和 $ 2 是extensions / part



我需要能够将csv文件的文件名传递给脚本,而不是在脚本中硬编码。如果任何人可以帮助我,我会真的很感激,因为我有超过50个这些子模块定期添加,我厌倦了一个一个写出来。

$ p

解决方案

由于你只有50个这样的子模块,你可以创建一个 bash 脚本来执行此操作

 #!/ bin / bash 
filename =$ 1

while IFS =,read one two
do
git submodule add$ one$ two
done< $ filename


I have no idea how to write Bash and after googling around for a while, I'm in no better position to achieve what I need. I have a csv file consisting of a list of git submodules and their paths-to-be in the super project:

git://github.com/demo/git-repo.git, extensions/git-repo
git://github.com/demo/another-repo.git, extensions/another-repo

I would like to have a bash script which would read each line of the file, put each part of the line (separated by the comma) into the following command

git submodule add $1 $2

$1 being the git:// part and $2 being the extensions/ part

I need to be able to pass the filename of the csv file to the script, and not have it hardcoded in the script. If anyone can help me, I would really appreciate it as I have over 50 of these submodules to add regularly, and I'm fed up with writing it out one by one.

Cheers.

解决方案

Since you only have 50 of these submodules, you can create a bash script to do this

#!/bin/bash
filename="$1"

while IFS="," read one two
do
  git submodule add "$one" "$two"
done < "$filename"

这篇关于如何做一个bash foreach csv字段为'git submodule add'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆