support BSD and GNU

By reversing for statement, support tail -r and tac