How to do a bash foreach csv field to 'git submodule add'

青春壹個敷衍的年華 提交于 2020-01-15 18:33:18

问题


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.


回答1:


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"


来源:https://stackoverflow.com/questions/5776984/how-to-do-a-bash-foreach-csv-field-to-git-submodule-add

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!