fork(4) download
  1. #!/bin/bash
  2.  
  3. if ${BASH_VERSION+\:} false; then
  4. shopt -s extglob lastpipe expand_aliases
  5. shopt -u assoc_expand_once
  6. fi
  7. case $(command -v let) in let) ;; *) let() while ${2+\:} return "$((! ( ${1:-0} )))"; do shift; done; esac
  8.  
  9. alias \
  10. n='let "(n += 1) >= max" && ' \
  11. c='printf "%s " "$n"; n alias c="printf \$(( (n -= 1) + 1))\ ;" n=; eval c c'
  12.  
  13. set -x
  14. n=0 max=9 command eval c echo
Success #stdin #stdout #stderr 0.01s 5356KB
stdin
Standard input is empty
stdout
0 1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 0 
stderr
+ n=0
+ max=9
+ command eval c echo
+ eval c echo
++ printf '%s ' 0
++ let '(n += 1) >= max'
++ eval c c echo
+++ printf '%s ' 1
+++ let '(n += 1) >= max'
+++ eval c c c echo
++++ printf '%s ' 2
++++ let '(n += 1) >= max'
++++ eval c c c c echo
+++++ printf '%s ' 3
+++++ let '(n += 1) >= max'
+++++ eval c c c c c echo
++++++ printf '%s ' 4
++++++ let '(n += 1) >= max'
++++++ eval c c c c c c echo
+++++++ printf '%s ' 5
+++++++ let '(n += 1) >= max'
+++++++ eval c c c c c c c echo
++++++++ printf '%s ' 6
++++++++ let '(n += 1) >= max'
++++++++ eval c c c c c c c c echo
+++++++++ printf '%s ' 7
+++++++++ let '(n += 1) >= max'
+++++++++ eval c c c c c c c c c echo
++++++++++ printf '%s ' 8
++++++++++ let '(n += 1) >= max'
++++++++++ alias 'c=printf $(( (n -= 1) + 1))\ ;' n=
++++++++++ eval c c c c c c c c c c echo
+++++++++++ printf '9 '
+++++++++++ printf '8 '
+++++++++++ printf '7 '
+++++++++++ printf '6 '
+++++++++++ printf '5 '
+++++++++++ printf '4 '
+++++++++++ printf '3 '
+++++++++++ printf '2 '
+++++++++++ printf '1 '
+++++++++++ printf '0 '
+++++++++++ echo