Advertisement
chusiang

do while example with sh

May 4th, 2012
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.68 KB | None | 0 0
  1. #!/bin/sh
  2. # do while example with sh, and It is the infinite loop.
  3. # tips from man sh.
  4.  
  5. # = Main =
  6. #f="0"
  7. #while : f
  8. #do
  9. #   f=$(($f + 1))    # like java`s "f = f + 1;"
  10. #
  11. #   if [ $f -lt 10 ]; then
  12. #       echo "0$f"
  13. #   else
  14. #       echo "$f"
  15. #   fi
  16. #   sleep 3
  17. #done
  18.  
  19. padtowidth=2
  20.  
  21. while : f
  22. do
  23.     f=$(($f + 1))    # like java`s "f = f + 1;"
  24.     printf "%0*d\n" $padtowidth $f;
  25.     sleep 3
  26. done
  27.  
  28.  
  29. # = Result =
  30. 01
  31. 02    # inter 3s.
  32. 03
  33. ...
  34.  
  35. # = Reference =
  36. # * In bash, how could I add integers with leading zeroes and maintain a specified buffer - Stack Overflow http://stackoverflow.com/questions/3191067/in-bash-how-could-i-add-integers-with-leading-zeroes-and-maintain-a-specified-b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement