[Home] Zsh logo

reverse

Zsh Wizard

Download reverse Return to Examples
  1. #!/usr/local/bin/zsh
  2. #
  3. # reverses all arguments by a divide-and-conquer method. Not very
  4. # efficient (takes log base 2 of n shells to do it) but kinda fun.
  5. if [[ $# -gt 1 ]]
  6. then
  7. local mid=$[$# / 2]
  8. echo $(reverse ${argv[$mid + 1, -1]}) $(reverse ${argv[1, $mid]})
  9. else
  10. echo ${argv[1]}
  11. fi