tag:blogger.com,1999:blog-6637736252081011583.post5323687064241098762..comments2023-10-23T11:13:47.199-07:00Comments on Daily Vim: Text Editor Tips, Tricks, Tutorials, and HOWTOs: Bash For LoopsTravis Whittonhttp://www.blogger.com/profile/14592647486468034166noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-6637736252081011583.post-43463811482923445532008-05-05T08:29:00.000-07:002008-05-05T08:29:00.000-07:00@steve:Didn't know about using seq, but that's a n...@steve:<BR/><BR/>Didn't know about using seq, but that's a nice trick. Backticking ls to glob expand files is indeed unnecessary. Although, there are times when a backtick in a loop context is helpful to operate on the output of an external command, it's overkill in this case.<BR/><BR/>@dag:<BR/><BR/>I didn't know that syntax. Thanks for the tip.<BR/><BR/>@anon:<BR/><BR/>Yup, find / exec is a really nice combo. Thanks for mentioning it.Travis Whittonhttps://www.blogger.com/profile/14592647486468034166noreply@blogger.comtag:blogger.com,1999:blog-6637736252081011583.post-64427076741840739712008-05-01T23:55:00.000-07:002008-05-01T23:55:00.000-07:00find . -maxdepth 5 -type f -iname "*.txt" -exec ec...find . -maxdepth 5 -type f -iname "*.txt" -exec echo {} \;<BR/><BR/>This does same job like file loop in blog but<BR/>* ignores case of filename (-iname)<BR/>* recursively with maximum depth of 5 sub dirs (-maxdepth)<BR/>* listing only regular files (-type) (f=files, d=dirs)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6637736252081011583.post-362768327818989322008-04-30T16:13:00.000-07:002008-04-30T16:13:00.000-07:00The zsh shell also allows this shortened syntax fo...The zsh shell also allows this shortened syntax for single-command loops:<BR/><BR/>for f (*.txt) echo "file $f"Daghttps://www.blogger.com/profile/10043613422923060743noreply@blogger.comtag:blogger.com,1999:blog-6637736252081011583.post-56334465240302022702008-04-30T09:10:00.000-07:002008-04-30T09:10:00.000-07:00Couple things:1) I'm not sure if it's more portabl...Couple things:<BR/><BR/>1) I'm not sure if it's more portable, but I've always preferred `seq M N` when N-M is large, instead of the ((...)) form.<BR/><BR/>2) I've seen a lot of people use the "for i in `ls *.txt`" form, and I've not quite understood the appeal: "for i in *.txt" is identical, I'm told more portable, and shorter.Steve Lanielhttps://www.blogger.com/profile/15382641193477770243noreply@blogger.com