Shachar Hamuzim Rajuan February 2016

running command in loop by properties file Shell script

I want to run git command to to create new branch, The command is:

git checkout -b branch1.00 branch1.00

Now I want to run this command when instead of "branch1.00" I will have a parameter (lets call it $branch) , this parameter will take it's value from a .properties file (lets call that file prop.properties) and run this command on all values in this file.

So if the prop.properties file will look like that:

branch=branch1.00
branch=branch2.00
branch=branch3.00
branch=branch4.00

The git command will run 4 times like that:

git checkout -b branch1.00 branch1.00
git checkout -b branch2.00 branch2.00
git checkout -b branch3.00 branch3.00
git checkout -b branch4.00 branch4.00

Any idea how to do that?

Answers


anubhava February 2016

This while loop with do the job:

while IFS='=' read -r _ b; do
   git checkout -b "$b" "$b"
done < prop.properties

If there is no branch= prefix then use:

while read -r b; do
   git checkout -b "$b" "$b"
done < prop.properties

This will run these commands:

git checkout -b branch1.00 branch1.00
git checkout -b branch2.00 branch2.00
git checkout -b branch3.00 branch3.00
git checkout -b branch4.00 branch4.00

Post Status

Asked in February 2016
Viewed 2,788 times
Voted 10
Answered 1 times

Search




Leave an answer