|
Prev: china nike factory wholesale Air Max 90,Air Max 95,Air Max180,Air Max 36,nike max ltd
Next: simple makefile help
From: naumfuieu2000 on 16 Apr 2008 14:09 --------- code #!/bin/bash LIST="01 02 03 04 05 06 07 08 09 10" for element in $LIST do workOn($element) # For each element do something if [ "$?" -ne "0" ] # If the output from the last command/ function was not "success" = 0, then then export LIST="$LIST $element" # add the current element to the bottom of the list, to try again later fi done --------- code That doesn't work. I suppose once bash reads the line "for element in $LIST" it does the expansion and work on each element it read, from that point does not matter the contents of $LIST, right? I could use a while loop and keep trying to "workOn()" the current element until it gives a exit status 0/success, but that will delay the other elements. Is that possible to dynamically change a for() loop? If so, is it correct the way I'm working with lists? This script notifies all registered users when a watched file is altered, I connect directly to their mail hosts (resolve the MX for the domain and telnet to it). thanks
From: mop2 on 16 Apr 2008 14:27 Using while: #!/bin/bash LIST="01 02 03 04 05 06 07 08 09 10" LIST="$LIST ";NOW= while [ "$LIST" ];do NOW=${LIST%% *} LIST=${LIST#* } echo your_operation $NOW || LIST="$LIST $NOW" # append if error done Dont tested! naumfuieu2...(a)yahoo.com.br wrote: > --------- code > #!/bin/bash > > LIST="01 02 03 04 05 06 07 08 09 10" > > for element in $LIST > do > workOn($element) # For each element do something > if [ "$?" -ne "0" ] # If the output from the last command/ > function was not "success" = 0, then > then > export LIST="$LIST $element" # add the current element > to the bottom of the list, to try again later > fi > done > --------- code > > That doesn't work. I suppose once bash reads the line "for element in > $LIST" it does the expansion and work on each element it read, from > that point does not matter the contents of $LIST, right? > I could use a while loop and keep trying to "workOn()" the current > element until it gives a exit status 0/success, but that will delay > the other elements. > > Is that possible to dynamically change a for() loop? If so, is it > correct the way I'm working with lists? > > This script notifies all registered users when a watched file is > altered, I connect directly to their mail hosts (resolve the MX for > the domain and telnet to it). > > thanks
From: Ed Morton on 16 Apr 2008 23:35
On 4/16/2008 1:09 PM, naumfuieu2000(a)yahoo.com.br wrote: > --------- code > #!/bin/bash > > LIST="01 02 03 04 05 06 07 08 09 10" > > for element in $LIST > do > workOn($element) # For each element do something > if [ "$?" -ne "0" ] # If the output from the last command/ > function was not "success" = 0, then > then > export LIST="$LIST $element" # add the current element > to the bottom of the list, to try again later > fi > done > --------- code > > That doesn't work. I suppose once bash reads the line "for element in > $LIST" it does the expansion and work on each element it read, from > that point does not matter the contents of $LIST, right? > I could use a while loop and keep trying to "workOn()" the current > element until it gives a exit status 0/success, but that will delay > the other elements. > > Is that possible to dynamically change a for() loop? If so, is it > correct the way I'm working with lists? > > This script notifies all registered users when a watched file is > altered, I connect directly to their mail hosts (resolve the MX for > the domain and telnet to it). > > thanks If I were you, I'd separate the re-tries from the initial list so you can add controls on how many retry attempts to make, etc. if you like. Something like this: LIST="01 02 03 04 05 06 07 08 09 10" todo="$LIST" while [ -n "$todo" ] do succ="" fail="" for element in $todo do workOn($element) # For each element do something if [ "$?" -eq "0" ]; then succ="$succ $element" else fail="$fail $element" fi done echo "Succeeded:$succ" echo "Failed:$fail" todo="$fail" done would be very easy to instrument (and it'd work!). If you don't need to keep LIST around after the loop, just use that directly instead of "todo". Ed. |