Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hey all i am writing my first bash script. and i am making it install all the repos i have on github.

warpInLocations=("git@github.com:acc/toolkit.git" "git@github.com:acc/sms.git" "git@github.com:acc/boogle.git" "git@github.com:acc/cairo.git")

so those are them so when i install them

echo "warping in toolkit, sms, boogle and cairo"
for repo in "${warpInLocations[@]}"
  warpInDir=$(echo ${warpToLocation}${repo} | cut -d'.' -f1)
  if [ -d "$warpToLocation"]; then
    echo "somethings in the way.. $warpInDir all ready exists"
    git clone $repo $warpInDir


this line here i wanted it to give me a folder named toolkit or sms so after the / and before the . in the warp in locations but its selecting git@github instead i guess because its after the .

how can i get it to select the name in the repo??

share|improve this question
That's a bit confusing. What do you want? The string between the last / and the following .? – Uwe May 24 '13 at 14:54
each instance of the the warpInLocations – TheLegend May 24 '13 at 14:56
up vote 7 down vote accepted
dir=$(basename git@github.com:acc/toolkit.git .git)

will set $dir to toolkit.

also useful is the dirname command.

share|improve this answer

You need to proceed in two steps:

dir=${dir#*/}                       # Remove everything up to /
dir=${dir%.*}                       # Remove everything from the .
share|improve this answer

in bash, you can also use a regular expression and capturing parentheses

for repo in "${warpInLocations[@]}"; do
    [[ $repo =~ /([^.]+)\. ]] && dir=${BASH_REMATCH[1]}
    # ...
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.