问题
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