Skip to content

Instantly share code, notes, and snippets.

@kirbysayshi
Forked from theoperatore/iterations_even_odd
Last active December 11, 2015 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirbysayshi/4678439 to your computer and use it in GitHub Desktop.
Save kirbysayshi/4678439 to your computer and use it in GitHub Desktop.
i=0; FILES=$(ls -tr ./); for FILE in $FILES; do i=$(($i + 1)); if [$(($i % 2)) = 0]; then echo"$i$FILE"; fi; done;
outputs:
==>
-bash: [0: command not found
-bash: [1: command not found
-bash: [0: command not found
...
...
...
<==
#!/bin/bash
i=0
FILES=$(ls -tr ./)
for FILE in $FILES; do
i=$(($i + 1))
isEven=$(($i % 2))
if [ "$isEven" -eq 0 ]; then
echo "$i$FILE"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment