Assuming all your URLs have one of these forms:
https://github.com/user1/repo1.git
https://github.com/user2/repo1.git
git@github.com:user3/repo2.git
git@github.com:user4/repo2.git
you can define a Bash function like this:
clone() {
local url=$1
local repo=${url%.git} # remove .git suffix if need be
repo=${repo##*/} # remove largest prefix upto last slash
local org=${url%/*} # remove suffix from last slash
org=${org##*[/:]} # remove largest prefix upto slash or colon
( set -x; # verbose mode
git clone "$url" "$org.$repo" )
}
Then you can do indeed:
for i in $(cat repolist.txt); do clone "$i"; done
One advantage of using this syntax (${parameter#word}
, ${parameter%word}
, etc.) over basename
and dirname
is that no extra process is spinned, since this parameter expansion feature is builtin in Bash.
Finally, as explained in the SO question Read a file line by line assigning the value to a variable (mentioned by Benjamin W.), you can avoid the $(cat repolist.txt)
phrasing and run the following command:
while IFS= read -r line || [ -n "$line" ]; do clone "$line"; done < repolist.txt
which is more efficient; and also more robust in case a line contains spaces (even if this situation won't occur here).