Quantcast
Channel: Active questions tagged retry-logic - Stack Overflow
Viewing all articles
Browse latest Browse all 950

Retry a command only once : when a command fails (in bash)

$
0
0
 for ( i=3; i<5; i++) do   execute some command 1   if command 2 is successful then do not run the command 1 (the for loop should continue)   if command 2 is not successful then run command 1 only once (like retry command 1 only once, after this the for loop should continue)    done

This is to note that command 2 is dependent on command 1 and command 2 can only be executed after command 1

for example:

 for ( i=3; i<5; i++) do    echo "i">> mytext.txt   ---> command 1     if "check the content of mytext.txt file to see if the value of i is  actually added" ---> command 2      if it is not added then execute echo "i">> mytext.txt (command 1) again and only once.    if i value is added to the file .. then exit and continue the loop  done

Since the "command 1" is quite big and not just an example echo statement here.I do not want to add "command 1" twice .. once outside and once inside the if condition. I want this logic in an optimized way with no redundancy of code.


Viewing all articles
Browse latest Browse all 950

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>