LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-19-2021, 11:38 PM   #1
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

Rep: Reputation: 0
Question 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?
 
Old 09-20-2021, 01:23 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,945

Rep: Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325
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
 
1 members found this post helpful.
Old 09-20-2021, 07:12 AM   #3
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

Original Poster
Rep: Reputation: 0
Thank you and Beautiful!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Issue In Using Maxdepth AnkitRauthan Linux - Newbie 3 10-24-2017 01:26 PM
[SOLVED] Cannot 'find "[" -maxdepth 1 -wholename "/usr/bin/[" ! \( -perm /g+w,o+w \)' standard_output Linux - General 5 09-13-2013 04:23 PM
[SOLVED] find maxdepth and print only the maxdepth matches cli Linux - Newbie 4 06-11-2013 12:36 PM
fedora4+cbq+maxdepth problem sumonhere Linux - Networking 1 03-17-2007 03:45 AM
Simulating mindepth, maxdepth in find subu_s Programming 1 04-11-2005 05:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration