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
这里要注意命令2依赖于命令1,命令2只能在命令1之后执行
例如:
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
由于“命令 1”非常大,而不仅仅是此处的示例 echo 语句。我不想添加两次“命令 1”......一次在 if 条件之外,一次在 if 条件内。我希望这种逻辑以一种优化的方式,没有代码冗余。