Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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[@]}"
do
  warpInDir=$(echo ${warpToLocation}${repo} | cut -d'.' -f1)
  if [ -d "$warpToLocation"]; then
    echo "somethings in the way.. $warpInDir all ready exists"
  else
    git clone $repo $warpInDir
  fi

done

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
add comment

3 Answers 3

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
add comment

You need to proceed in two steps:

dir=git@github.com:acc/toolkit.git
dir=${dir#*/}                       # Remove everything up to /
dir=${dir%.*}                       # Remove everything from the .
share|improve this answer
add comment

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

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

Your Answer

 
discard

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.