OK, this is a "well, DUH" for any reader with any technical ability, I'm sure, but I don't care. I became addicted to foreach in tcsh, but a lot of machines I admin want to use bash as the default shell, so I figured I should learn that. Problem is, I never can remember the equivalent of "foreach i (echo *)" when I want to do things to lots of files in cwd at once. So, here's one way to do it, for my own reference:

list=`echo *`  
for file in $list  
do  
do_stuff_to $file here  
done  

Update - I could do it like this too:

for file in `echo *`

as Somebody pointed out. Generally that's better, but sometimes I might like to reuse $list too. Depends on situation.


Published

Category

Technology

Contact