I agree, Daniel.
I should have said, I have a bunch of working scripts that use the first form 'for' loop, so I was really bugged why modifying them was giving me so much trouble. Turns out that my troubles have to do with BASH shell expansion of command lines, the order and precedence of shell expansion. There are workarounds, but more complicated than just switching to third or fourth form of 'for' loop. Thanks for your quick reply and good suggestion, Daniel! John Daniel Eggleston wrote: > Why not use the fourth form? It lends itself much more nicely to > programmatic assignment... > > On Thu, Jul 2, 2009 at 10:15 PM, Blues Renegade > <[email protected] <mailto:[email protected]>> wrote: > > > > I know of 4 different ways to use a for loop. Here they are for those > that aren't aware of all 4 ways. > > |1. for I in {1..10}; do echo $I; done| > > |2. for I in 1 2 3 4 5 6 7 8 9 10; do echo $I; done| > > |3. for I in $(seq 1 10); do echo $I; done| > > |4. for ((I=1; I <= 10 ; I++)); do echo $I; done > | > That being said, I have a script I'm trying to modify to use a > variable > instead of a fixed hard-coded value, using the 1st form of the for > loop. I've tried all different ways of quoting and escaping the > variable, and the main problem is that the quoting chars or escape > char > are beinh translated and passed into the loop as well as the value > stored in the variable. > > For example, to change the start value of 1 to whatever value I want > passed in thru a variable: > > for i in {1..100}; do <something>; done > > to: for i in {$a..10}; do <something>; done > > I have tried: {{$a}..10} and {`$a`..10}, to have the variable > evaluated > first. > I have tried the using the eval() function. > I have tried single and double quotes and the backslash escape > character. > > Nothing I've tried works. Yes, maybe I should try using a > different form > of the for loop, but it bugs me that I can't get this form of the > for to > work properly. It's probably a stupid syntax error on my part, but as > of now, I'm baffled. > > Can anyone shed some light on the problem and solution, please? > Thanks! > > John > ||| > > > > > > | > > > > > > -- > > Daniel --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Linux Users Group. To post a message, send email to [email protected] To unsubscribe, send email to [email protected] For more options, visit our group at http://groups.google.com/group/linuxusersgroup -~----------~----~----~----~------~----~------~--~---
