Reputation: 318
Don't be to hard on me this is my first bash attempt since school (like 9 years ago).
I'm trying to create a script that will rsync remote git repos locally.
I want to store my local directory into a variable because I'm using it several times but I don't find how to do it with the wildcard I use in the for loop.
I tried to concatenate the "/*/" and some other things that I didn't really understood but nothing worked.
Here is my script :
#!/bin/bash
if [ "$#" -lt 1 ]; then
echo "Usage :"
echo "syncDown <repo1> <repo2> ..."
echo "syncDown --all"
exit 1;
fi
LOCAL_PATH="/Volumes/Case Sensitive/repos"
# Sync all local repos
if [ $1 = "--all" ]; then
# for dir in "$LOCAL_PATH/*/";do <-- What I tried
for dir in /Volumes/Case\ Sensitive/repos/*/;do # <-- What works
folder=$(echo $dir | rev | cut -d'/' -f2 | rev);
rsync -avzh --delete-after devweb:$folder --exclude ".git" --exclude ".idea" "$LOCAL_PATH"
done
# Sync specific repos
else
for repo in "$@"; do
rsync -avzh --delete-after devweb:$repo --exclude ".git" --exclude ".idea" "$LOCAL_PATH"
done
fi
Thanks for your help.
Upvotes: 2
Views: 2070
Reputation: 784998
You should be using:
for dir in "$LOCAL_PATH"/*/; do
Make sure to not keep glob character in quote and quote only the variable.
Upvotes: 3