LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Recursive loop for maxdepth=1 does not work (https://www.linuxquestions.org/questions/linux-newbie-8/recursive-loop-for-maxdepth%3D1-does-not-work-4175700855/)

sysmicuser 09-19-2021 11:38 PM

Recursive loop for maxdepth=1 does not work
 
Good Morning/Afternoon/Evening All,

I am in a parent directory and I have repositories like below. It is a very rapid development environment and I want to automate git pull so no matter if I am working or not on any repo, every day I should do a git pull before I start with my work.

Directories are as below:
+ ls --color=auto
Code:

AGL-IAC                GO5-IAC                  ST8-IAC        learn-terraform-locals          terraform-azurerm-application-gateway  terraform-azurerm-security-groups
Azure-IaC-Buildsheet    GO7-IAC                  TST-IAC        tenancy-instances              terraform-azurerm-eventhub            terraform-azurerm-storage-account


My hacky shell script is like below:


Code:

for dir in *;  do  [ -d "$dir" ] && cd "$dir" && git remote -v && git pull & cd ..; done;
+ for dir in *
[2] 281
+ cd ..
+ '[' -d AGL-IAC ']'
+ for dir in *
+ cd AGL-IAC
+ git remote -v
[3] 282
+ '[' -d Azure-IaC-Buildsheet ']'
+ cd ..
+ for dir in *
[4] 284
+ cd ..

As you see above it is not working as expected, how to make it work properly, and is it possible to set Azure Repo Userid and PAT Token so I do not have to enter it when the script runs?

pan64 09-20-2021 01:23 AM

An & is missing:
Code:

for dir in *;  do  [ -d "$dir" ] && cd "$dir" && git remote -v && git pull && cd ..; done;
from the other hand:
Code:

for dir in *;  do  [ -d "$dir" ] && git -C "$dir" remote -v && git -C "$dir" pull; done;
probably better

sysmicuser 09-20-2021 07:12 AM

Thank you and Beautiful!!


All times are GMT -5. The time now is 05:38 PM.