Hi
Today we will learn, how to loop through directory or folder with shell script.
Some days ago, working on a project, we have a requirement where we have to change the origin of a app directory. Because we have shifted our git repository to another server. There were 500 apps. So changing manually for each directory, it was time consuming.
What we do then, made a shell script for looping through each directory and excute a command to change origin.
First I made a origin.sh file in root folder and put the below script in that file.
And now run the file with below command in terminal
By running this command, it will excute the command written in origin.sh file.
It will loop through each directory of given path and excute the command.
Thanks
Today we will learn, how to loop through directory or folder with shell script.
Some days ago, working on a project, we have a requirement where we have to change the origin of a app directory. Because we have shifted our git repository to another server. There were 500 apps. So changing manually for each directory, it was time consuming.
What we do then, made a shell script for looping through each directory and excute a command to change origin.
First I made a origin.sh file in root folder and put the below script in that file.
#!/bin/bash
for f in /home/username/your_directory_path/apps/*;
do
[ -d $f ] && cd "$f" && git remote set-url origin your_new_origin_url
done;
And now run the file with below command in terminal
sh ./origin.sh
By running this command, it will excute the command written in origin.sh file.
It will loop through each directory of given path and excute the command.
Thanks