Take the 2-minute tour ×

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.


share|improve this question
Depending on the actual contents of those repositories, you might consider some recursive submodules, bundling up those over 50 into a more manageable number. –  Jefromi Apr 25 '11 at 12:17
I would love to, but they are all separate extensions to a CMS system. –  Designermonkey Apr 25 '11 at 14:25
add comment

1 Answer

up vote 5 down vote accepted

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


while IFS="," read one two
  git submodule add "$one" "$two"
done < "$filename"
share|improve this answer
So I could do between 20 and 200 with this if I wanted then? –  Designermonkey Apr 25 '11 at 9:51
yes, as long as you have 20-200 of each of these separated by commas like in your sample. It should be fine. –  ghostdog74 Apr 25 '11 at 9:55
add comment

Your Answer


